Solved Use a date value in string

foshizzle

Registered User.
Local time
Today, 14:33
Joined
Nov 27, 2013
Messages
277
I'm trying to run the VBA below to delete table records based on a certain date.
The date is selected by the user in a form control then set to TempVars using TempVars!tmpEndDate = Me.txtEndDate.Value

Code:
Dim strSQL As String
strSQL = "Delete * From [tblBalance] WHERE [TransactionDate] =  " & CDate(TempVars!tmpStartDate)
DoCmd.RunSQL strSQL

The value of strSQL is Delete * From [tblBalance] WHERE [TransactionDate] = 4/4/2023

I believe this is failing to delete because the date is included as part of the string.
How can I get around this?
 
strSQL = "Delete * From [tblBalance] WHERE [TransactionDate] = #" & CDate(TempVars!tmpStartDate) & "#"
 
ok the hash tags make sense. Thanks! This worked!
 
Be aware that format must be mm/dd/yyyy
With that date you have there, it is ambiguous. :(
 

Users who are viewing this thread

Back
Top Bottom