• Help with error message (2003 sp2)

    Author
    Topic
    #447398

    I cannot understand why I get the error message “invalid uses of Null” in this procedure at the first line beginning “IF Left(Me…”. It worked fine when I first tested it and now it does not.

    The intention is to test for a 12/25 or 7/4 (any year) date and if true make a button on the form visible.

    Private Sub Combo17_AfterUpdate()
    ‘ Find the record that matches the control.
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst “[ASSET_NUMBER] = ‘” & Me![Combo17] & “‘”
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    If Left(Me.INSPECT_DATE, Len(Me.INSPECT_DATE) – 5) = “07/04” Then
    Me.cmd_ARC1.Visible = True
    End If
    If Left(Me.APPRAISE_DATE, Len(Me.APPRAISE_DATE) – 5) = “12/25” Then
    Me.cmd_ARC2.Visible = True
    End If
    End Sub

    Viewing 0 reply threads
    Author
    Replies
    • #1090906

      If the control INSPECT_DATE is blank you’d get this error message, so you should check for that before the If statement, e.g.

      If IsNull(Me.INSPECT_DATE) Then
      MsgBox “Please enter a date!”, vbExclamation
      Me.INSPECT_DATE.SetFocus
      Exit Sub
      End If

      • #1090920

        Why don’t I think of these things? bummer However, null is valid for the Inspect_Date field if an inspection has never been done. I know, we never seem to give enough information.

        I changed the line to If Left(Me.INSPECT_DATE, 5) = “07/04” Then and I do not get any errors.

        I can’t help wondering why it works when it essentially says the same thing.

        • #1090927

          Left(Null, 5) returns Null, and Null doesn’t equal “07/04”, so that works as intended.

          Len(Null) is not 0 but Null, so Left(Null, Len(Null)-5) evaluates to Left(Null, Null) and VBA can’t handle this.

    Viewing 0 reply threads
    Reply To: Help with error message (2003 sp2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: