Invalid use of null error message (1 Viewer)

Malcy

Registered User.
Local time
Today, 03:52
Joined
Mar 25, 2003
Messages
586
Hi
I have a problem on one form which I cannot fathom. When I hit the OK button I get an error message saying "Invalid use of null" but I cannot see where I am referring to a null.
There is quite a lot of code on the button but the starting bit (which is where my hunch is the problem lies since the error comes up instantly) is
Code:
' Data identification for MP Christmas movements
    Dim lngPat As Long
    Dim intStartDay As Integer
    Dim dtmEndDate As Date
    Dim lngDrug As Long
    Dim lngDose As Long
    Dim lngCntId As Long
    Dim strScript As String
    Dim dtmStartDate As Date
    
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    If Me.TCntDispPatt = 0 Then
            MsgBox "You must enter a dispensing pattern for the script.", vbOKOnly, "Required Data"
            Me.TCntDispPatt.SetFocus
        Exit Sub
    End If

' Populate variables for MP Christmas movements
    lngPat = DLookup("TCntDispPatt", "tblTmpScriptContents")
    intStartDay = DLookup("TCntStartDay", "tblTmpScriptContents")
    dtmEndDate = DLookup("TCntEndDate", "tblTmpScriptContents")
    lngDrug = DLookup("TCntDrug", "tblTmpScriptContents")
    lngDose = DLookup("TCntDoseId", "tblTmpScriptContents")
    strScript = DLookup("TCntScrNo", "tblTmpScriptContents")
    lngCntId = DLookup("TcntId", "tblTmpScriptContents")
    dtmStartDate = DLookup("TCntStartDate", "tblTmpScriptContents")
    
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
There is more which I could post if anyone is interested.

Intriguingly if I cancel the error message, switch to design view, then switch straight back to form view and hit the button it runs perfectly.
I feel sure this says a lot to someone who knows what it is saying!
Any help greatly appreciated
Best wishes
 

Mile-O

Back once again...
Local time
Today, 03:52
Joined
Dec 10, 2002
Messages
11,316
You don't say which line causes the error but I'll guess that it is:

Code:
lngPat = DLookup("TCntDispPatt", "tblTmpScriptContents")

If it is this line then this is because the DLookup is not finding a value. Use the Nz() function to make a return value.

i.e.

Code:
lngPat = Nz(DLookup("TCntDispPatt", "tblTmpScriptContents"))

This is true for all your lookups.
 

Malcy

Registered User.
Local time
Today, 03:52
Joined
Mar 25, 2003
Messages
586
Thanks that sorted the error message
Interestingly it threw up some other processing issues and I have tracked down that I should have been pulling that variable for the textbox rather than from a background table. It also explains why when I went to design and back it works since that would have written the textbox to the table! One grows older and wiser (with some expert help)
I have also added the Nz to the other lookups.
Anyway thanks for your help
Best wishes
 

Users who are viewing this thread

Top Bottom