Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If then run query

Status
Not open for further replies.

Drenda

Programmer
Joined
Sep 1, 2007
Messages
85
Location
GB
Wonder if anyone can help

Is it possible to run a query from code based on an if statement

For example

If [control]= "Control" Then RunQuery

If this is possible would you know the correct way to write this code

Many thamks
 
What type of query do you want to run (select, totals, crosstab, append, delete, maketable,...)?

By [Control] do you mean a control on a form? How about providing some real control and query names?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Ok it goes something like this

Private Sub USD_Code_AfterUpdate()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If [USD Code] = "CAP" Then stDocName = "Cost Authorisation Form Delete Query When CON Selected"
DoCmd.OpenQuery stDocName, acNormal, acEdit

End Sub

Hope this makes sense
 
Can we assume this is a delete query? How does this work?
Code:
Private Sub USD_Code_AfterUpdate()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If [USD Code] = "CAP" Then 
    stDocName = "Cost Authorisation Form Delete Query When CON Selected"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
End Sub


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks for you help

I've actually managed to sort this, it is a delete query and was scheduled to run if the value of a control on a form ="CAP"
I now run a function if the control = "CAP" which runs the delete query and it seems to work

Once again Many thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top