Results 1 to 2 of 2

Thread: Handling errors

  1. #1
    Join Date
    Sep 2011

    Unanswered: Handling errors


    I have writen the code under to be able to fill automatically the field "ARTICLE" when the field "CBARRE" is field first.
    This code works perfectly but when I input a wrong CBARRE number or when I live the field blank, I receive an error message "Error 94 - Unvalid use of Null"

    Can you help me replace this error with a personnalized message box or just ignore it.

    Private Sub CBARRE_Exit(Cancel As Integer)

    Dim txtARTICLE1 As String
    Dim txtPVUTTC1 As String
    txtARTICLE1 = DLookup("ARTICLE1", "tblCBARRE", "CBARRE1 =[CBARRE]")
    txtPVUTTC1 = DLookup("PVUTTC1", "tblCBARRE", "CBARRE1 =[CBARRE]")
    If (Not IsNull(txtARTICLE1)) Then Me![ARTICLE] = txtARTICLE1
    If (Not IsNull(txtPVUTTC1)) Then Me![PVUTTC] = txtPVUTTC1

    End Sub

  2. #2
    Join Date
    May 2005
    Nevada, USA
    Provided Answers: 6
    Well, the basics of error trapping since you asked:

    Error trapping

    But I believe in avoiding errors that you can anticipate, and this is an instance of that. You get an error because a String variable can't accept a Null, which is what the DLookup will return when it can't find a result. Changing String to Variant will avoid the error.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts