Solved Checking a value is empty/null/0 etc. Run-time error 13 Type mismatch (1 Viewer)

Chief

Registered User.
Local time
Yesterday, 16:12
Joined
Feb 22, 2012
Messages
156
Hello,
I've had a look thru some of the forums, but nothing to match my current error if I could get some advice please.

I have a check box and then a combo box.
On form close I go thru some checks to ensure certain fields are filled out correctly.
This particular one is given me grief. Run-time error 13 Type mismatch

I select "Skilled Labour" try and close and then code activates as combo box has nothing in it.
Works, all good, happy days.

However, when I select items in the combo box and try to close, I get the error.
1639098889477.png

1639098919986.png


Code:
' Check Skilled Labour Combo box
    If (ChkSkill = True) Then
        If Nz(Me.CboSkill) = "" Then
            txtmessage = "Skilled Labour has been chosen for this Job, Please Select Type of labour" & vbCrLf & txtmessage
            Me.CboSkill.BackColor = vbRed
            Me.CboSkill.ForeColor = vbWhite
            Me.CboSkill.SetFocus
        Else
            Me.CboSkill.BackColor = vbWhite
            Me.CboSkill.ForeColor = vbBlack
        End If
    End If

Thank you :)
 

June7

AWF VIP
Local time
Yesterday, 15:12
Joined
Mar 9, 2014
Messages
5,475
Is this combobox bound to a multi-value field?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 00:12
Joined
Jul 9, 2003
Messages
16,282
Try changing
Code:
If Nz(Me.CboSkill) = "" Then
to
Code:
If Nz(Me.CboSkill, 0) = 0 Then
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 00:12
Joined
Jul 9, 2003
Messages
16,282
Thank you, Tried that and still error.
Let's have a look and see what's in the combo box then... try this:-

Code:
' Check Skilled Labour Combo box
    If (ChkSkill = True) Then
MsgBox " >>> " &  Me.CboSkill
        If Nz(Me.CboSkill) = "" Then

What does the message box return??
 

Chief

Registered User.
Local time
Yesterday, 16:12
Joined
Feb 22, 2012
Messages
156
Solved :rolleyes:
Sorry for such a simple error.

Thank you for replies :)(y)

Code:
' Check Skilled Labour Combo box
    If (ChkSkill = True) Then
        If IsNull(Me.CboSkill) Then
            txtmessage = "Skilled Labour has been chosen for this Job, Please Select Type of labour" & vbCrLf & txtmessage
            Me.CboSkill.BackColor = vbRed
            Me.CboSkill.ForeColor = vbWhite
            Me.CboSkill.SetFocus
        Else
            Me.CboSkill.BackColor = vbWhite
            Me.CboSkill.ForeColor = vbBlack
        End If
    End If
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:12
Joined
May 7, 2009
Messages
19,245
you can also check:

If Me.CboSkill.ListIndex = -1

meaning, no Valid item from the combobox was selected.
what does this mean?
you can type anything in the combo and may not be a valid combo item.
therefore:

IsNull(Me.CboSkill), will be false, yet not a valid combo selection.
 

Users who are viewing this thread

Top Bottom