Invalid SQL on INSERT

D

Doctor

I continue to get an "invalid SQL error" with the following SQL. When I copy
the sql from the immediate window into a query, it runs fine.

Here is the code generating the sql statment.

'Create Link in tblLLCRegLink
If Not IsNothing(strGroupID) Then
Me.LLCRegGroupID.Requery
Me.LLCRegGroupID.Value = strGroupID
strSQLa = "INSERT tblLLCRegLink ( LLCRegGroupID, LLCRegID ) " & _
"SELECT " & strGroupID & " AS Expr1, " & strGroup & " AS Expr2 ;"
Debug.Print strSQLa
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL2
DoCmd.SetWarnings True
Me.sfrmLLCRegLink.Requery


Here is a sample SQL statement generated in the Immediate window.

INSERT INTO tblLLCRegLink ( LLCRegGroupID, LLCRegID ) SELECT 9 AS Expr1, 281
AS Expr2 ;

I'm not sure what to do. Any help would be tremendously appreciated.

Thanks.



And may I say, I love this site! Constantly find help here (even if I only
post once a month or so) Kudos to those of you who are willing to help those
like me.
 
D

Dorian

How are your columns defined (LLCRegGroupID, LLCRegID )?
Where is your FROM clause?
Why do you have 'As Expr1' and 'As Expr2'?

-Dorian
 
C

Cyberwolf0000 via AccessMonster.com

Doctor said:
I continue to get an "invalid SQL error" with the following SQL. When I copy
the sql from the immediate window into a query, it runs fine.

Here is the code generating the sql statment.

'Create Link in tblLLCRegLink
If Not IsNothing(strGroupID) Then
Me.LLCRegGroupID.Requery
Me.LLCRegGroupID.Value = strGroupID
strSQLa = "INSERT tblLLCRegLink ( LLCRegGroupID, LLCRegID ) " & _
"SELECT " & strGroupID & " AS Expr1, " & strGroup & " AS Expr2 ;"
Debug.Print strSQLa
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL2
DoCmd.SetWarnings True
Me.sfrmLLCRegLink.Requery

Here is a sample SQL statement generated in the Immediate window.

INSERT INTO tblLLCRegLink ( LLCRegGroupID, LLCRegID ) SELECT 9 AS Expr1, 281
AS Expr2 ;

I'm not sure what to do. Any help would be tremendously appreciated.

Thanks.

And may I say, I love this site! Constantly find help here (even if I only
post once a month or so) Kudos to those of you who are willing to help those
like me.


You have the DoCmd.RunSQL set to strSQL2 and you are building a strSQLa

--
James B Gaylord
For the Wolf comes the strength of the Pack,
For the Pack comes the strength of the Wolf,
-R. Kipling
Office 2003 on Win XP SP2
 
D

Dirk Goldgar

Doctor said:
I continue to get an "invalid SQL error" with the following SQL. When I
copy
the sql from the immediate window into a query, it runs fine.

Here is the code generating the sql statment.

'Create Link in tblLLCRegLink
If Not IsNothing(strGroupID) Then
Me.LLCRegGroupID.Requery
Me.LLCRegGroupID.Value = strGroupID
strSQLa = "INSERT tblLLCRegLink ( LLCRegGroupID, LLCRegID ) " &
_
"SELECT " & strGroupID & " AS Expr1, " & strGroup & " AS Expr2
;"
Debug.Print strSQLa
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL2
DoCmd.SetWarnings True
Me.sfrmLLCRegLink.Requery


Here is a sample SQL statement generated in the Immediate window.

INSERT INTO tblLLCRegLink ( LLCRegGroupID, LLCRegID ) SELECT 9 AS Expr1,
281
AS Expr2 ;


There's something odd here, because the code you posted doesn't include the
"INTO" keyword in building strSQLa, but you have it in what you say was
printed in the Immediate window. Also, the code you posted *builds*
strSQLa, but *executes* strSQL2. Did you type all the code into your
message freehand, rather than copying and pasting? Or is are these
discrepancies the cause of your error?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top