AppendEquivalent

AccessAmateur

Registered User.
Local time
Today, 00:29
Joined
Feb 13, 2003
Messages
30
What is the VBA code equivalent to an append query?
Query SQL is:
INSERT INTO Table1 ( NBR )
SELECT Table2.NBR
FROM Table2;
Thanks
 
There is no "equivalent" - you either just open/run the query. If you have it stored then you can just use:

DoCmd.OpenQuery "MyQuery"


Another method is to literially build it as a string variable.

and then use the DoCmd.RunSQL command to run it. This method only works with Action queries.


So:

Code:
Dim strSQL As String

strSQL = "INSERT INTO Table1 ( NBR ) SELECT Table2.NBR FROM Table2;"

DoCmd.RunSQL strSQL


If you don't want the warnings:

Code:
Dim strSQL As String

strSQL = "INSERT INTO Table1 ( NBR ) SELECT Table2.NBR FROM Table2;"

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
 
You can also avoid the warnings by calling using the Execute method:

For DAO:
Currentdb.Execute strSQL

For ADO:
CurrentProject.Connection.Execute strSQL
 
Look up AddNew to find VBA code samples for inserting records.
 

Users who are viewing this thread

Back
Top Bottom