Help with Avoiding Invalid Use of Null

belly0fdesire

Registered User.
Local time
Today, 11:47
Joined
Dec 1, 2005
Messages
11
I am using the following function created in a module:

Code:
Public Function StraightTimeLookup(ByVal UName As String, _
                            ByVal dat1 As Date) As Integer

    StraightTimeLookup = DLookup("[StraightTime]", "StraightTime", _
                  "[User] = '" & UName & _
                  "' AND [Date] = #" & dat1 & "#")
End Function

I am then using this as the default value of a field in a form. It is going to lookup what the user puts in as a date and return the value for that user on that date. But if there is nothing entered for that date, it returns an invalid use of Null error. Is there a way around this.

Sorry... I'm still very new at this. Thanks in advance for your help.




PS I would like to have it just return a zero when there is nothing entered for that date...
 
Last edited:
Code:
If Isnull(dat1) Then
     StraightTimeLookup = 0
Else
     StraightTimeLookup = DLookup("[StraightTime]", "StraightTime", _
                  "[User] = '" & UName & _
                  "' AND [Date] = #" & dat1 & "#")
End If
 
Okay... NZ() around the formula... I got it.. as usual i figured it out on my own, but thank you to anyone that considered helping me..


EDIT: just saw your response... thank you very much!
 
Code:
Public Function StraightTimeLookup(ByVal UName As String, ByVal dat1 As Date) As Integer
    If IsNull(dat1) then
        StraightTimeLookup = 0
    Else
        StraightTimeLookup = DLookup("[StraightTime]", "StraightTime", "[User] = '" & UName & "' AND [Date] = #" & dat1 & "#")
    End if
End Function
 

Users who are viewing this thread

Back
Top Bottom