I need to check if the date in a field is today's.
The table containing the field only has one record, and will never have more than one record.
I have tried two pieces of code:
The above code is inefficient because it does a DLookUp twice. I need to do the DLookUp twice because I need to test for a null value. If I just have DLookup("LastLogInDate", "tblCompanyDetails") <> Date and "LastLogInDate" is null I get an error
In the code above "LastLogInDate" is not today's date!
What is the most efficient method to adopt?
Thanks in advance
The table containing the field only has one record, and will never have more than one record.
I have tried two pieces of code:
Code:
Dim dteLastLogInDate As Date
If IsNull(DLookup("LastLogInDate", "tblCompanyDetails")) Or DLookup("LastLogInDate", "tblCompanyDetails") <> Date Then
dteLastLogInDate = DLookup("LastLogInDate", "tblCompanyDetails")
If IsNull(dteLastLogInDate) Or dteLastLogInDate <> Date Then
DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblCompanyDetails set LastLogInDate = " & Date
DoCmd.SetWarnings True
End If
Code:
Dim dteLastLogInDate As Variant
If IsNull(DLookup("LastLogInDate", "tblCompanyDetails")) Or DLookup("LastLogInDate", "tblCompanyDetails") <> Date Then
dteLastLogInDate = DLookup("LastLogInDate", "tblCompanyDetails")
If IsNull(dteLastLogInDate) Or dteLastLogInDate <> Date Then
DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblCompanyDetails set LastLogInDate = " & Date
DoCmd.SetWarnings True
End If
What is the most efficient method to adopt?
Thanks in advance