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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Code Error 1

Status
Not open for further replies.

lars7

Technical User
Aug 16, 2005
817
GB
Hi can anyone see whats wrong with this Insert code.

Private Sub Command2_Click()
CurrentDb.Execute "INSERT INTO INSERT INTO tbltest (name,date,number,) VALUES" _
& "('" & Me!text1 & "'" _
& ",#" & Format(Me!Text2, "yyyy-mm-dd") & "#" _
& "," & Me!Text3 & ")"
End Sub

I keep getting a "Syntax error in INSERT INTO statement"
 
There's one additional/excess comma after the last field in the column list. If these are your real field names, use brackets [tt]([name], [date], [number])[/tt], as at least two of them are reserved words.

Roy-Vidar
 
Hi Roy,
I tried it without that comma and added the brackets but got the same result.

CurrentDb.Execute "INSERT INTO INSERT INTO tbltest ([name],[date],[number]) VALUES" _
& "('" & Me!text1 & "'" _
& ",#" & Format(Me!Text2, "yyyy-mm-dd") & "#" _
& "," & Me!Text3 & ")"
End Sub

When I tried to do this on a bigger scale in my staff table I was getting the error so I created this smaller scale test table and fields to try it in but still no luck.
 
I didn't see you where repeating the INSERT INTO keywords too.

Roy-Vidar
 
Thanks Roy,
I should be more carefull when I'm copying and pasting. :~/ Your backets and removing the comma have worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top