Insert into syntax error - Its probably something easy

CodyMonster

Board Regular
Joined
Sep 28, 2009
Messages
159
I'm getting a syntax error for the insert into part of this code..
I'm probably doing something easy and just over looking a " or something.
Totally frustrated.

Code:
Dim strSQL As String

BWreportdate = XlApp.Range("A13").Value   '<-- this is a date in Excel

strSQL = "insert into 9-Daily_Physical_Date([Date])" & "Values(#BWReportDate#);"
DoCmd.RunSQL strSQL
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Now trying it this way..
I have the date I need in another table..[2-date_Aquire]![Date-0]
Getting Run-Time Error '3134': Syntax Error in Insert Into statement

any help would be appreciated.

Code:
If DCount("*", "9-Daily_Physical_Date") = 0 Then
Dim strSQL As String
strSQL = "Insert into 9-Daily_Physical_Date([Date]) values([2-date_Aquire]![Date-0]);"
Debug.Print strSQL
CurrentDb.Execute strSQL
 
Last edited:
Upvote 0
"insert into 9-Daily_Physical_Date([Date])" & "Values(#BWReportDate#);"
"INSERT INTO 9-Daily_Physical_Date([Date]) VALUES (#" & BWReportDate "#);"

"Insert into 9-Daily_Physical_Date([Date]) values([2-date_Aquire]![Date-0]);"
"INSERT INTO 9-Daily_Physical_Date([Date]) VALUES (#" & [2-date_Aquire]![Date-0] & "#);"

Methinks the issue is missing # around your date value or in first case, it is in the wrong place. If neither of these work, post your debug.print result.
Observations:
- Looks like you have a field called [Date]. Date is a reserved word, so this would be bad form.
- Never use special characters (exception: _ ) in object names. I have seen situations where 9-Daily would be interpreted as "9 minus Daily".
- If [Date-0] is a field name, it's another bad form example. However, if it's supposed to be [Date]-0, I think you have it wrong.
I would opt to see if the first example works before dealing with the second, because you've made a few changes and might have introduced additional problems that my suggestion won't fix.
 
Last edited:
Upvote 0
Did what you suggested, now getting..
Run-time Error '424': Object required

The reason for the 9-Daily is mostly to track the sequence of tables being created. By putting a number in front of it, I can follow the routine.
I can just take out the "-"
Same with the [Date-0], which is just the current date. I have [Date-1] which is the previous day. I can just change these to [Date_0] and [Date_1]

Thanks for the help..
Hopefully I can get this up and running soon.
 
Upvote 0
the error strongly suggests the problem is with your code, not the sql. suggest you post the code and indicate on which line(s) the error(s) generate what error numbers & message text. Debug print your sql, paste it into a new query and see if it works to determine there aren't any issues with that also.
 
Upvote 0
Code:
If DCount("*", "9-Daily_Physical_Date") = 0 Then
Dim strSQL As String
[I]strSQL = "Insert into 9-Daily_Physical_Date([Date]) values(#" & [2-date_Aquire]![Date-0] & "#);"[/I] <----error
Debug.Print strSQL
CurrentDb.Execute strSQL

Debug.Print output
Code:
Insert into 9-Daily_Physical_Date([Date]) values(#[2-date_Aquire]![Date-0]#);

Maybe its the naming of the fields that is a problem..?
 
Upvote 0
[Debug.Print output
Insert into 9-Daily_Physical_Date([Date]) values(#[2-date_Aquire]![Date-0]#);
Maybe its the naming of the fields that is a problem..?

Your parameter is not being resolved. This should be a date - like 01/01/2015
 
Upvote 0
So, in order to break down where the problem might be.. I started to look at each aspect of the DB.
Code:
Dim d As Database
Dim r As Recordset
Dim CurrentDate As Field
Set d = CurrentDb()
Set r = d.OpenRecordset("[2DateAquire]")
Set CurrentDate = ["Date_0"]

I changed the name of the table from 2-Date_Aquire to 2DateAquire. Just to fix any bad form.
But now I get Run-time error 3078
cannot find the input table or query [2DateAquire].
Its spelled correctly. Its there. But this is most likely why the date is not being resolved.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,836
Messages
6,127,173
Members
449,368
Latest member
JayHo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top