I'm trying to run an Access delete query when I close my Excel workbook. I want the DELETE query to delete any record that is prior to today's date in the "ResDate" field. Below is the code I have written. The workbook closes but the records remain in the database (TR table).
I thought this would work but am striking out so far. Any suggestions on getting this to work would be greatly appreciated. Thanks for the help...…….
Const ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\MyDatabase\TRC.mdb;Persist Security Info=False"
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set Connection = New ADODB.Connection
Connection.ConnectionString = ConnectionString
Connection.Open
VSQL = "DELETE * FROM [TR] WHERE [TR].ResDate < " & Date
Set RecSet1 = Connection.Execute(VSQL, dbrows, adCmdText)
Connection.Close
Set RecSet1 = Nothing
End Sub