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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute a query per code 2

Status
Not open for further replies.

kingz2000

Programmer
May 28, 2002
304
0
0
DE
Hi,

I just want to know how to simpkly execute a query which already exists in a MS Access MDB as code!?

 
Have a look at the DoCmd.OpenQuery method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I believe the above answer is enough but just incase you didnt want the query to actually exist as an object, you could run the SQL statement that the query is running from by using Docmd.RunSQL function
 
As additional comments, the docmd.openquery works for "select" queries. You can use the RunSql code for action queries such as update, append and make table queries. I insert the debug.print function so that if the SQL string has bugs, I can go to the immediate window and copy the SQL string and paste it into a query for a quick solution to the problem. For us older programmers, that sometimes works better than trying to analyze the text in a long SQL string.

dim strsql as string

strsql = "UPDATE BudgetFLNew SET BudgetFLNew.2007Budget = '" & Format(Me.Totals1, "Currency") & "' " _
& "WHERE (((BudgetFLNew.PROPID)='" & Me.PROPID & "') AND ((BudgetFLNew.GLNO)=" & Me.GLNO & "));"
debug.print strsql
DoCmd.SetWarnings False
DoCmd.RunSQL strsql
DoCmd.SetWarnings True
 
the docmd.openquery works for "select" queries
In fact it works for ANY saved query.
 
PHV is absolutely correct. I focus too much on the SQL code for action queries.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top