VBA value of Yes/No in combo box?

garywood84

Registered User.
Local time
Today, 12:01
Joined
Apr 12, 2006
Messages
168
I have a form with a combo box on it, linked to a field which contains data in "Yes/No" format. I want an IF statement behind a button which will do one thing if the value in the combo box is yes, and another thing if it's no.

Can anyone tell me how to write a statement that says "If the value of combo box = "yes"? It seems that VBA sees yes and no as numerical values, but I can't find out what values!

Thanks,

Gary
 
Hi,

you can use the true/false

Code:
If Me.Fieldname = True Then
  'Code goes here
Else
 'code for false goes here
End If
 
maxmangion,

Thanks for your reply. However, I'm still having problems getting it working.

This is the code I currently have:
Code:
If Me!lstTreasurer.ItemsSelected.Count > 0 Then
    If Me!lstTreasurer.Value = -1 Then
        strCriteria6 = "bqryBoardMembersContactDetails.[Treasurer] = Yes"
    Else
        strCriteria6 = "bqryBoardMembersContactDetails.[Treasurer] = No"
    End If
Else
    strCriteria6 = ""
End If

The embedded If is not working, because whether Yes or No is selected in the combo box, strCriteria6 always gets set to the latter value, i.e. ... .[Treasurer] = No.

Can anyone tell me what I've done wrong?

Thanks,

Gary
 
Code:
If Me!lstTreasurer.ItemsSelected.Count > 0 Then
    If Me!lstTreasurer.Value = -1 Then
        strCriteria6 = "bqryBoardMembersContactDetails.[Treasurer] = Yes"
    Else
        strCriteria6 = "bqryBoardMembersContactDetails.[Treasurer] = No"
    End If
Else
    strCriteria6 = ""
End If

Presumes that the value in the combo box is either -1 or something else. But we can't see what is stored by the action in question. We can't see what value was selected by a combo box. So it is hard to diagnose.

If you REALLY REALLY REALLY meant Yes/No then use either a check box - for which the .Value is generally TRUE/FALSE - or a Radio Button Group with a TRUE button and a FALSE button, such that the button group value is either true or false. (Be sure to define a default value for the group in order for this to work right, because if you don't, it won't.)
 
I would suggest finding out what the combo is actually returning.

either add a message box in the combo's after update event

MsgBox Me.YourComboNameHere

or use the

Debug.Print

in the same event to see in the Immediate window (in the VBA area) what is actually being returned. Then adjust your code accordingly.
 

Users who are viewing this thread

Back
Top Bottom