mshelton23
New Member
- Joined
- Jun 14, 2019
- Messages
- 5
I've looked everywhere for a solution to this issue with no luck. I'm using ADO to connect a workbook to a second workbook and then update certain fields in the second workbook. I can get this to work perfectly on any data type except a date. The second workbook has a column called Timestamp set to "yyyy-mm-dd" format. I'd like for the appropriate cells (based on criteria) in the Timestamp column to be updated with the current date. Everything I've tried yields the "Syntax Error in UPDATE statement" error. Here is my code below where I'm trying to update two lines (based on ID of 59 and 60) with a Timestamp. Any help is very much appreciated!!!
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 in (59,60)"
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 in (59,60)"
Dim conn As New ADODB.Connection
With conn
.Open connStr
.Execute mySQL
.Close
End With
Set conn = Nothing