SQL Statement

fodzilla

Board Regular
Joined
Jun 16, 2011
Messages
120
Hi Guys,

Been working on something for a while and now have an issue with something in the below statement.

Anyone able to help out?

strSQL = "INSERT INTO tbl_TM1_Volumes ( TM1UniqueKey, Site, Date, Time_Band, Number_of_Exits ) " & _
" VALUES (" & _
"" & Sheet1.Cells(iRow, 1) & ", " & _
"" & Sheet1.Cells(iRow, 2) & ", " & _
"" & Sheet1.Cells(iRow, 3) & ", " & _
"" & Sheet1.Cells(iRow, 4) & ", " & _
"" & Sheet1.Cells(iRow, 5) & " )"

Looks fine to me but still erroring.
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

fodzilla

Board Regular
Joined
Jun 16, 2011
Messages
120
Here is my full code:

Private Sub Workbook_open()


Dim strSQL As String
Dim iRow As Long

Call ConnectDatabase

For iRow = 2 To 150


' strSQL = "INSERT INTO tbl_TM1_Volumes ( Site ) " & _
' " VALUES (" & _
' "" & Sheet1.Cells(iRow, 2) & ") "

strSQL = "INSERT INTO tbl_TM1_Volumes ( TM1UniqueKey, Site, Date, Time_Band, Number_of_Exits ) " & _
" VALUES (" & _
"" & Sheet1.Cells(iRow, 1) & ", " & _
"" & Sheet1.Cells(iRow, 2) & ", " & _
"" & Sheet1.Cells(iRow, 3) & ", " & _
"" & Sheet1.Cells(iRow, 4) & ", " & _
"" & Sheet1.Cells(iRow, 5) & " )"


' MsgBox strSQL
DBCONT.Execute strSQL



Next iRow


Call CloseDatabase
End Sub
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
Hi

Please post the specifics of the error. Please post the sample data that is associated with it.

How are the dates stored in the worksheet? In the database. Which fields are text?

Please post the SQL as it shows in the msgbox (or just debug.print strSQL).

Field name Date could be a problem, btw. Maybe better to either change it to [Date] or re-name it, or give it an explicit table prefix.

Are there any nulls in the data?

For interest, a thread from not too long ago : http://www.mrexcel.com/forum/excel-...ations-export-data-ms-access-table-print.html

regards
 
Last edited:

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
Are the fields and data types consistent between the database and Excel? To resolve these sort of questions specific info needs to be provided. cheers
 

Watch MrExcel Video

Forum statistics

Threads
1,122,694
Messages
5,597,571
Members
414,156
Latest member
WDMix

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
Top