Solved

Insert into table

Posted on 2014-02-13
3
233 Views
Last Modified: 2014-02-14
Hi,

this is VB access database.  I can insert one record but if I try to insert more than one I get a systax error.

I am not sure why.

This will insert fine for one record.

CurrentDb.Execute "INSERT INTO [Report_1_MTD_Daily_Containment] ([LOB], [CreatedDate], [Call_Count], [Contained_Calls])" _
& "(,'WMI', #" & MyDate & "#, '" & WMICount & "', '" & WMIContained & "');"

I want to do this:

CurrentDb.Execute "INSERT INTO [Report_1_MTD_Daily_Containment] ([LOB], [CreatedDate], [Call_Count], [Contained_Calls])" _
& "VALUES ('DC', #" & MyDate & "#, '" & DCCount & "', '" & DCContained & "')" _
& "(,'WMI', #" & MyDate & "#, '" & WMICount & "', '" & WMIContained & "');"

it says missing semicolon

Thanks,
Lulu
0
Comment
Question by:lulu50
3 Comments
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 39857462
You can't do that. You have to run the query twice with one set of values.

Or use DAO and VBA. Much nicer and cleaner.

/gustav
0
 
LVL 19

Accepted Solution

by:
Ken Butters earned 250 total points
ID: 39857483
I think are you trying to insert two rows worth of data?

If so... I believe that needs to be separated into two insert statements.

Also noticed on your last line... a leading comma right after the open parenthesis...

Corrected statements should be something like this:

CurrentDb.Execute "INSERT INTO [Report_1_MTD_Daily_Containment] ([LOB], [CreatedDate], [Call_Count], [Contained_Calls]) " _
& "VALUES ('DC', #" & MyDate & "#, '" & DCCount & "', '" & DCContained & "')";

CurrentDb.Execute "INSERT INTO [Report_1_MTD_Daily_Containment] ([LOB], [CreatedDate], [Call_Count], [Contained_Calls]) " _
& "VALUES ('WMI', #" & MyDate & "#, '" & WMICount & "', '" & WMIContained & "');"
0
 

Author Closing Comment

by:lulu50
ID: 39858857
Thank you
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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.

828 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