Solved

Syntax error in INSERT INTO string

Posted on 2009-07-05
2
318 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 142

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now