Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Why getting invalid use of null

I have the following code in the not in list event of a combobox on a form.  But when I enter a value that is not in the list I get an invalid use of null message.  ????

Private Sub cboInsurance_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
Dim NewID As String

On Error GoTo Err_CustomerID_NotInList

    If NewData = "" Then Exit Sub

    Msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
    Msg = Msg & "Do you want to add it?"
    If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
        Response = acDataErrContinue
        MsgBox "Please try again."
    Else
        Set db = CurrentDb
        Set Rs = db.OpenRecordset("tblInsuranceCompaniesLU", dbOpenDynaset)

        Msg = "Please enter an insurance company name" & vbCr & "InsuranceCompany."
        NewID = Me.cboInsurance   '.Value        'InputBox(Msg)
        Rs.FindFirst BuildCriteria("InsuranceCompany", dbText, NewID)

        Do Until Rs.NoMatch
           NewID = InputBox("InsuranceCompany " & NewID & " already exists." & _
                    vbCr & vbCr & Msg, NewID & " Already Exists")
           Rs.FindFirst BuildCriteria("InsuranceCompany", dbText, NewID)
        Loop

        Rs.AddNew

        Rs![InsuranceCompany] = NewID

        Rs![InsuranceCompany] = NewData

        Rs.Update

        Response = acDataErrAdded

    End If

Exit_CustomerID_NotInList:
       Exit Sub
Err_CustomerID_NotInList:
       ' An unexpected error occurred, display the normal error message.
       MsgBox Err.Description
       ' Set the Response argument to suppress an error message and undo
       ' changes.
       Response = acDataErrContinue

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial