SQL of a query

mlopes1

Registered User.
Local time
Yesterday, 20:21
Joined
Sep 4, 2002
Messages
76
I created an append query, viewed its SQL code, copied it and pasted into the OnClick event of a form button.

Here is what I pasted:

INSERT INTO Total_List ( [Company#], Company_Name)
SELECT Selected.SlctCompany, Selected.Slct_Company2
FROM Selected;


I keep receiving a syntax error in code? What am I missing? First time trying this so bare with me if stupid question.


Marco
 
well, it depends on what you´re trying to do. I think you need to create a querydef. Look up querydef and maybe recordset in the help files.

Fuga.
 
Try removing the semi colon fom the end of the SQL string.

Jon.
 
Marco,
If you want to run the query in code enter this into the onclick event procedure:

Code:
DIM strSQL as string

strSQL = "INSERT INTO Total_List ( [Company#], Company_Name) " & _
"SELECT Selected.SlctCompany, Selected.Slct_Company2 " & _
"FROM Selected"

docmd.runSQL strSQL
If you want to add variables to the SQL Statement use:
Code:
DIM strSQL as string

strSQL = "INSERT INTO Total_List ( [Company#], Company_Name) " & _
"SELECT " & me.txtCompNo & " AS compNo, '" &  me.txtCompName & "' AS compName"

docmd.runSQL strSQL
Dave
 

Users who are viewing this thread

Back
Top Bottom