M
mbentler
I am trying to use a value in a Date/Time field in my code:
Public Function GetDays() As Integer
'Determine the number of days on an insurance policy
Dim dteStart As Date
Dim dteEnd As Date
Dim VarDays As Variant
Dim Insurance As Date
Dim varX As Variant
'Find value in the Insurance field
varX = DLookup("[CompanyName]", "tblCompanyList", "[Insurance] = "
& Forms!frmCompanyList!Insurance)
dteStart = Now()
dteEnd = varX
VarDays = DateDiff("d", dteStart, dteEnd)
Debug.Print VarDays
' Tell user the status of the companies insurance policy
If (VarDays >= 10) Then
MsgBox "Insurance Valid", vbOKOnly + vbInformation, "Insurance
Status"
ElseIf (VarDays < 10) And (VarDays > 2) Then
MsgBox "Insurance About to Expiry", vbOKOnly + vbExclamation,
"Insurance Status"
ElseIf (VarDays < 2) Then
MsgBox "Insurance Expired", vbOKOnly + vbCritical, "Insurance
Status"
End If
End Function
When running I get an "Invalid use of Null" even when there is a value
in the Insurance field.
Any suggestions
Public Function GetDays() As Integer
'Determine the number of days on an insurance policy
Dim dteStart As Date
Dim dteEnd As Date
Dim VarDays As Variant
Dim Insurance As Date
Dim varX As Variant
'Find value in the Insurance field
varX = DLookup("[CompanyName]", "tblCompanyList", "[Insurance] = "
& Forms!frmCompanyList!Insurance)
dteStart = Now()
dteEnd = varX
VarDays = DateDiff("d", dteStart, dteEnd)
Debug.Print VarDays
' Tell user the status of the companies insurance policy
If (VarDays >= 10) Then
MsgBox "Insurance Valid", vbOKOnly + vbInformation, "Insurance
Status"
ElseIf (VarDays < 10) And (VarDays > 2) Then
MsgBox "Insurance About to Expiry", vbOKOnly + vbExclamation,
"Insurance Status"
ElseIf (VarDays < 2) Then
MsgBox "Insurance Expired", vbOKOnly + vbCritical, "Insurance
Status"
End If
End Function
When running I get an "Invalid use of Null" even when there is a value
in the Insurance field.
Any suggestions