Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT SQL STATEMENT

Status
Not open for further replies.

ParyGoal

MIS
Jul 22, 2006
70
US
Hello everyone

Can anyone see a problem with the following insert statement?
I am getting an error message that says
"Syntax error in insert statement"

strSQL = "INSERT INTO tblAuthorizedGroupsDetails (HECPID, Group ) "
strSQL = strSQL & "VALUES("
strSQL = strSQL & "'" & rsHECP.Fields("HECPID") & "',"
strSQL = strSQL & "'" & txtAuthorizedUsers.Tag & "')"



Both HECPID and Group fields are defined as integer.

Thank you

Parygoal
 
Numbers don't need quotes.

Code:
 strSQL = strSQL & rsHECP.Fields("HECPID") & ","

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
It is a good idea to cut and past it all onto one long string to see if you have the quotes and brackes OK
I would think it should be
INSERT INTO tblAuthorizedGroupsDetails (HECPID, Group ) VALUES (rsHECP.Fields("HECPID") , txtAuthorizedUsers.Tag )
 
Further to Ted's post it's even easier to use a
Code:
Debug.Print strSQL
when you're finished constructing it to see what would be inserted and check it looks right (you can/should even test the produced query in your DB of choice to see if it will work).

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Group" is a reserved word.
So enclose it in brackets:

[Group]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top