Sanjeet Prasad
Registered User.
- Local time
- Tomorrow, 09:19
- Joined
- Sep 18, 2006
- Messages
- 13
I have a script as below :
Public Sub DoSQL()
Dim SQL123 As String
Dim TEST As String
TEST = "23/01/2003"
SQL123 = "UPDATE AR_Invoice " & _
"SET AR_Invoice.IMPORT = 'Y' " & _
"WHERE AR_Invoice.InvoiceDate = '23/01/2003'"
DoCmd.RunSQL SQL123
End Sub
this script works fine and records are updated.
Now I want to use the same with date being a variable as below.The Dated variable is a global varibale which is captured from a form:
Public Sub DoSQL()
Dim SQL123 As String
Dim TEST As String
SQL123 = "UPDATE AR_Invoice " & _
"SET AR_Invoice.IMPORT = 'Y' " & _
"WHERE AR_Invoice.InvoiceDate = " & "'" & Dated & "'"
DoCmd.RunSQL SQL123
End Sub
I have noticed that when I hard code the date this works and when I use varibale this does not work.When I execute the script it says 0 records updated, when in fact it should updated 45 records for which I am sure.
I feel it is a conversion problem from date/time to string and vice versa.I hav e not been able to recify the problem.Hlep please.Thanks.
Public Sub DoSQL()
Dim SQL123 As String
Dim TEST As String
TEST = "23/01/2003"
SQL123 = "UPDATE AR_Invoice " & _
"SET AR_Invoice.IMPORT = 'Y' " & _
"WHERE AR_Invoice.InvoiceDate = '23/01/2003'"
DoCmd.RunSQL SQL123
End Sub
this script works fine and records are updated.
Now I want to use the same with date being a variable as below.The Dated variable is a global varibale which is captured from a form:
Public Sub DoSQL()
Dim SQL123 As String
Dim TEST As String
SQL123 = "UPDATE AR_Invoice " & _
"SET AR_Invoice.IMPORT = 'Y' " & _
"WHERE AR_Invoice.InvoiceDate = " & "'" & Dated & "'"
DoCmd.RunSQL SQL123
End Sub
I have noticed that when I hard code the date this works and when I use varibale this does not work.When I execute the script it says 0 records updated, when in fact it should updated 45 records for which I am sure.
I feel it is a conversion problem from date/time to string and vice versa.I hav e not been able to recify the problem.Hlep please.Thanks.