Type Mismatch Error

rrueger

Registered User.
Local time
Today, 13:52
Joined
May 19, 2011
Messages
10
Hello,
Having trouble with a type mismatch error.
I have form with 2 unbound combo boxes and 1 check box. The combo boxes are text boxes, the check box is a yes/no in table. Default Value of check box is 0. Lets call the combo boxes CMB1 and CMB2. and the Check box CK1

My code is breaking on the IF statement. (Not sure what the check box should be DIM as. Right now I have it
Dim CK1 as String

Code:
IF Me!CMB1 = "Choice1" or Me!CMB1 = "Choice2" and CK1="" and CMB2="" Then
Msgbox "You must make a selection", , "Invalid Selection"

I know its something stupid, like I need to DIM CK1 as something else, or change the value in the if statement from CK1 = "" to CK1= 0, CK1= False, or CK1= No.... but I've been playing with it and I can't figure it out.
 
A check box (i.e. a Yes/No field) is either True or False, not "". Also, if no selection is made in CMB2 then it is likely Null, not "". You can trap for this with the Nz function. Thirdly, the Or argument for the two choices in CMB1 should go in parentheses, so it will evaluate that first. The way you have it written now, if Choice1 is made in CMB1, it's going to ignore the evaluation of the check box and CMB2. It's like saying;

If CMB1 = "Choice1" then do something

Or

If CMB1 = "Choice2" And CK1="" And CMB2="" then do something

So your code should look more like the following;

Code:
If (Me!Cmb1 = "Choice 1" Or Me!Cmb1 = "Choice 2") And Me!CK1 = False And Nz(Me!Cmb2, "") = "" Then
MsgBox "You must make a selection", , "Invalid Selection"
End If
 

Users who are viewing this thread

Back
Top Bottom