Validation based on a Null condition problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kobamfo
    New Member
    • Sep 2012
    • 14

    Validation based on a Null condition problem

    Hi Guys,
    I have the following code which checks for non-Null fields prior to table update, so naturally, I have it on Before_Update of my form.

    Code:
    Dim strMessage As String
        Dim intOptions As Integer
        Dim strTitle As String
        Dim bytChoice As Byte
    
        If IsNull(destname) Then
            strMessage = "You have not entered a Destination for this Record." & _
            "Input a destination to continue" & vbCrLf & vbCrLf & _
            "Click ok to return to form."
            intOptions = vbOKOnly
            strTitle = "Missing Data..."
            bytChoice = MsgBox(strMessage, intOptions, strTitle)
    
            'If bytChoice = vbOKOnly Then
                'Set focus to the destname field            destname.SetFocus
    
    'highlight empty field
              
    Dim Green As Long
    Green = RGB(229, 238, 124)
    destname.BackStyle = 1
    destname.BackColor = Green
    
                'Cancel saving the record
                Cancel = True
            'End If
        End If
    Now I want this validation to work ONLY WHEN a field named "docref" Is Null and "destname" is also Null. If "docref" Is Not Null, then the validation should not pop-up and allow the form to save with "destname" being Null or zero length. (offcourse the backend table allows for zero lenght for the "destname" field. I hope my question is clear. :-|
    Any ideas please.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Use the AND operator.
    Code:
    If expression1 AND expression2 Then
       Do Something
    End If

    Comment

    • kobamfo
      New Member
      • Sep 2012
      • 14

      #3
      Thanks Rabbit, I think I am catching up a day at a time :-).

      Comment

      Working...