mshelton23
New Member
- Joined
- Jun 14, 2019
- Messages
- 5
I'm using ADO to connect one workbook to another and then update certain fields. This works with no issue with the exception of dates. The workbook being updated has a "Timestamp" column formatted as "yyyy-mm-dd." No matter what I try, the update fails when the SQL is run with the error "Syntax error in UPDATE statement." I've tried changing the numberformats, different data types, but nothing works. Here is my code below which always fails at ".Execute mySQL"
Dim ws As Worksheet
Dim myPath As String, connStr As String
Dim mySQL As String
Dim myDate As Date
myDate = Format(Date, "yyyy-mm-dd")
Set ws = ThisWorkbook.Sheets("Worklist")
myPath = <workbook path=""></workbook>
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & myPath & "';" & _
"Extended Properties=""Excel 12.0;HDR=YES"";"
mySQL = "UPDATE [Data$] " & _
"SET Timestamp = " & myDate & " " & _
"WHERE ID <some criteria=""></some>
Dim conn As New ADODB.Connection
With conn
.Open connStr
.Execute mySQL
.Close
End With
Set conn = Nothing
Dim ws As Worksheet
Dim myPath As String, connStr As String
Dim mySQL As String
Dim myDate As Date
myDate = Format(Date, "yyyy-mm-dd")
Set ws = ThisWorkbook.Sheets("Worklist")
myPath = <workbook path=""></workbook>
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & myPath & "';" & _
"Extended Properties=""Excel 12.0;HDR=YES"";"
mySQL = "UPDATE [Data$] " & _
"SET Timestamp = " & myDate & " " & _
"WHERE ID <some criteria=""></some>
Dim conn As New ADODB.Connection
With conn
.Open connStr
.Execute mySQL
.Close
End With
Set conn = Nothing