If IsNull, ElseIf IsNull

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
 
J

Jeff Cox

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
 
G

Guest

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

Maybe I have to turn the question around... Does If IsNotNull work the same?
 
D

Douglas J Steele

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?
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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
 
D

Douglas J Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

2 problems with code 3
two ComboBox questions 6
shorter method than elseif 1
Using Select case and isnull 5
Help with IF Statement 3
Will this IF work? 6
if... elseif statement 9
OnExit driving me crazy 3

Top