Full Version: vba code to auto click ok after SQL statement
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
Loosh
Hi. I have an SQL statement that appends records to a table:

SQL1 = "INSERT INTO [TBLTEMP_LOCHEAD]" & _
"SELECT LOCATION_HEADER2.*" & _
"FROM [LOCATION_HEADER2]" & _
Whereclause & _
"ORDER BY [TWP], [TDIR], [RNG], [RDIR], [SECTION]"
DoCmd.RunSQL (SQL1)

After this runs I get a popup box asking if I want to append these records. Is there a way to automatically append the records using vba code without having the popup box. Thank you.
freakazeud
Hi,
instead of using the RunSQL method try to execute your code with the .execute method e.g.:

CurrentDb.Execute "YourSQL", dbFailOnError

HTH
Good luck
Loosh
I dont think that works. It says it is unable to find the input table or query 'SQL1'. Thank you though.

Andrew
niesz
Remove the quotes. If you are passing in a variable as the SQL, you don't want to wrap the variable in quotes. VBA will think it is a literal.
Loosh
Cool. Thanks. That worked. Another quick question. When its running, the form kinda freezes until it is done. It doesnt give any indication that the SQL is running. Is there a way to make the cursor turn into the time capsule while its running? Thanks.

Andrew
NoahP
DoCmd.Hourglass True
CurrentDb.Execute SQL1,dbFailOnError
DoCmd.Hourglass False
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.