Link to home
Start Free TrialLog in
Avatar of bantamb20
bantamb20Flag for New Zealand

asked on

Syntax error in INSERT INTO string



I have moderate experience with VB in its various incarnations, a little experience with Access, and less with SQL. The syntax error I am getting here has me baffled.
I am trying write these eight variables to a table whose name is also a variable. The CREATE TABLE process works fine with the variable table name.
It's when I try to insert the data into the table that the fun begins.
I suppose it's something simple . . . but I have tried all the references I can find and no luck so far. Can someone help please?
(Using Access 2002, and vb 6.3)
=== Variables =====================  
Dim iClient As Integer
Dim iInstruct As Integer
Dim sActivity As String
Dim sACType As String
Dim sRego As String
Dim sDate As Date
Dim gDuration As Single
Dim sNotes As String
Dim sSQL As String
====================================
 
value for sTableName is passed to the subroutine 
other variables are loaded from text boxes and combo boxes on the form
 
 
 ===================================  
 
sSQL = "INSERT INTO " & sTablename & "[ClientNumber], [InstructorNumber], [ActivityType], [AircraftType], [AircraftRego], [Date], [Duration], [Notes] VALUES (" & iClient & "," & iInstruct & ",""' & sActivity & '"",""' & sACType & '"",""' & sRego & '"",""' & sDate & '""," & gDuration & ",""' & sNotes & '"")" 
 
 
CurrentDb.Execute sSQL
 
 
= The error message I get is: ================
 
Syntax error in INSERT INTO statement
 
=====================================

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bantamb20

ASKER

Thank you. I have been staring at that for about an hour and completely overlooked that mistake. It works now and I can get on with other things. Cheers and have a good week