I want to update a date field (called dater) in a table called tbldate.
The function dow gets the week day based on the system clock e.g dow= 4
The function prevdate then calculates which date to use based on a Select Case, e.g 28/07/2009
The problem lies in the function dated, the Debug.Print strsql shows the following: UPDATE tbldate SET tbldate.dater = 28/07/2009
But when I check the updated field (dater) it has the value 30/12/1899. Can anyone help
The function dow gets the week day based on the system clock e.g dow= 4
The function prevdate then calculates which date to use based on a Select Case, e.g 28/07/2009
The problem lies in the function dated, the Debug.Print strsql shows the following: UPDATE tbldate SET tbldate.dater = 28/07/2009
But when I check the updated field (dater) it has the value 30/12/1899. Can anyone help
Code:
Public Function dow()
dow = Weekday(Now())
End Function
-------------------------------------------------------------------------
Public Function prevdate()
Select Case dow
'dow is Tue (3) to Sat (7)
Case 3 To 7
prevdate = Date - 1
Debug.Print prevdate
Case Else
prevdate = Date - 3
Debug.Print prevdate
End Select
End Function
--------------------------------------------------------------------------
Public Function dated()
Dim strsql As String
Dim db As Database
DoCmd.SetWarnings False
strsql = ("UPDATE tbldate SET tbldate.dater = " & prevdate & "")
'Print the SQL so we can paste into the query build if there are errors
Debug.Print strsql
'Use Current Database
Set db = CurrentDb()
'Run the SQL Query
DoCmd.RunSQL strsql
DoCmd.SetWarnings True
End Function