Solved

Syntax error in INSERT INTO string

Posted on 2009-07-05
2
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

636 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