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.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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
 
Upvote 0
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:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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