Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2012
    Posts
    16

    Unanswered: Using VBA to check if record field is null

    Is it possible to use SQL like an IF statement? Mainly checking if a particular record's field is null, and if it is null fill it with whatever's in an attached textbox. If not, throw up an error.

    Any ideas on how to do something like that?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. For checking at a Table (or Query) level:
    Code:
    Dim strCriteria As String
    strCriteria = "[Identity Field Name] = " & Value 'e.g. "RowID = " & Me.RowID.Value
    If Isnull(DLookUp("Column Name", "Table (or Query) Name", strCriteria)) Then
        ' Do whatever you want when the Field is null.
    Else
        ' Do whatever you want when the Field is not null.
    End If
    2. The same but to raise an error when the Field is Null:
    Code:
    Dim strCriteria As String
    strCriteria = "[Identity Field Name] = " & Value 'e.g. "RowID = " & Me.RowID.ValueDim str As String
    '
    ' If DLookUp returns Null, Run-time error 94: Invalid use of Null will be raised.
    '
    str = CStr(DLookUp("Column Name", "Table (or Query) Name", strCriteria))
    Have a nice day!

Posting Permissions

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