SQL of a query (1 Viewer)

mlopes1

Registered User.
Local time
Today, 04:12
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
 

Fuga

Registered User.
Local time
Today, 09:12
Joined
Feb 28, 2002
Messages
566
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.
 

JonH

Registered User.
Local time
Today, 08:12
Joined
Oct 11, 2002
Messages
38
Try removing the semi colon fom the end of the SQL string.

Jon.
 

dgm

Registered User.
Local time
Today, 17:12
Joined
Sep 5, 2002
Messages
146
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

Top Bottom