Solved

Syntax error in INSERT INTO string

Posted on 2009-07-05
2
328 Views
Last Modified: 2012-05-07


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
Comment
Question by:bantamb20
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24779546
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
 

Author Closing Comment

by:bantamb20
ID: 31599903
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question