Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

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

0
bantamb20
Asked:
bantamb20
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you are missing the ( ) around the column namme list :
sSQL = "INSERT INTO " & sTablename & "( [ClientNumber], [InstructorNumber], [ActivityType], [AircraftType], [AircraftRego], [Date], [Duration], [Notes] ) VALUES (" & iClient & "," & iInstruct & ",""' & sActivity & '"",""' & sACType & '"",""' & sRego & '"",""' & sDate & '""," & gDuration & ",""' & sNotes & '"")" 

Open in new window

0
 
bantamb20Author Commented:
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now