If IsNull, ElseIf IsNull

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to check if either one of two cbo's is Null or if both are...

==========================
If IsNull(Me.cboA And Me.cboB) Then
MsgBox "cboA and cboB are empty"

ElseIf IsNull(Me.cboA) Then
MsgBox "cboA is empty"

ElseIf IsNull(Me.cboB) Then
MsgBox "cboB is empty"
End If
==========================

The strange thing is, that when I do this check, outcomes of the MsgBoxes
are not right. Isn't this the right method to check?

Thanks in advance... Jochem
 
Jochem said:
I want to check if either one of two cbo's is Null or if both are...

==========================
If IsNull(Me.cboA And Me.cboB) Then
MsgBox "cboA and cboB are empty"

ElseIf IsNull(Me.cboA) Then
MsgBox "cboA is empty"

ElseIf IsNull(Me.cboB) Then
MsgBox "cboB is empty"
End If
==========================

Try
If IsNull(Me.cboA) And IsNull(Me.cboB) Then
MsgBox "cboA and cboB are empty"

Hope this helps,

Jeff Cox
 
Thanks Jeff, but it didn't make any difference.

Maybe I have to turn the question around... Does If IsNotNull work the same?
 
There is no IsNotNull function.

I just tested:

If IsNull(Me.cboA) And IsNull(Me.cboB) Then
MsgBox "cboA and cboB are empty"
ElseIf IsNull(Me.cboA) Then
MsgBox "cboA is empty"
ElseIf IsNull(Me.cboB) Then
MsgBox "cboB is empty"
End If

and it worked as I expected it to. What problem are you encountering?
 
Hi guys,

I'm very very sorry, I gave the wrong example. It just happens when there is
a extra cbo in play.. like this:

Private Sub click_Click()
If IsNull(Me.cboA) And IsNull(Me.cboB) And IsNull(Me.cboC) Then
MsgBox "cboA and cboB and cboC are empty"
ElseIf IsNull(Me.cboA) Then
MsgBox "cboA is empty"
ElseIf IsNull(Me.cboB) Then
MsgBox "cboB is empty"
ElseIf IsNull(Me.cboC) Then
MsgBox "cboB is empty"
End If
End Sub
 
Try this for instance... it just doesn't work...

Private Sub click_Click()
If IsNull(Me.cboA) And IsNull(Me.cboB) And IsNull(Me.cboC) Then
MsgBox "cboA and cboB and cboC are empty"
ElseIf IsNull(Me.cboA And Me.cboC) Then
MsgBox "cboA and cboC are empty"
ElseIf IsNull(Me.cboA And Me.cboB) Then
MsgBox "cboA and cboB are empty"
ElseIf IsNull(Me.cboA) Then
MsgBox "cboA is empty"
ElseIf IsNull(Me.cboB) Then
MsgBox "cboB is empty"
ElseIf IsNull(Me.cboB And Me.cboC) Then
MsgBox "cboB and cboC are empty"
ElseIf IsNull(Me.cboC) Then
MsgBox "cboB is empty"
End If
End Sub
 
Try this:

---------------------
Private Sub cmd_Click()


If IsNull(Me.cboA) And IsNull(Me.cboB) And IsNull(Me.cboC) Then
MsgBox "cboA and cboB and cboC are empty"

ElseIf IsNull(Me.cboA) And IsNull(Me.cboC) Then
MsgBox "cboA and cboC are empty"

ElseIf IsNull(Me.cboA) And IsNull(Me.cboB) Then
MsgBox "cboA and cboB are empty"

ElseIf IsNull(Me.cboB) And IsNull(Me.cboC) Then
MsgBox "cboB and cboC are empty"

ElseIf IsNull(Me.cboA) Then
MsgBox "cboA is empty"

ElseIf IsNull(Me.cboB) Then
MsgBox "cboB is empty"

ElseIf IsNull(Me.cboC) Then
MsgBox "cboC is empty"

Else
MsgBox "alles ok"

End If


End Sub
 
You're still using IsNull incorrectly when you're checking pairs of combo
boxes. You've also got the wrong message for your last condition:

Private Sub click_Click()
If IsNull(Me.cboA) And IsNull(Me.cboB) And IsNull(Me.cboC) Then
MsgBox "cboA and cboB and cboC are empty"
ElseIf IsNull(Me.cboA) And IsNull(Me.cboB) Then
MsgBox "cboA and cboB are empty"
ElseIf IsNull(Me.cboA) And IsNull(Me.cboC) Then
MsgBox "cboA and cboC are empty"
ElseIf IsNull(Me.cboB) And IsNull(Me.cboC) Then
MsgBox "cboB and cboC are empty"
ElseIf IsNull(Me.cboA) Then
MsgBox "cboA is empty"
ElseIf IsNull(Me.cboB) Then
MsgBox "cboB is empty"
ElseIf IsNull(Me.cboC) Then
MsgBox "cboC is empty"
End If
End Sub
 
Back
Top