Combo Box Value (1 Viewer)

Smokeeater

Registered User.
Local time
Yesterday, 20:48
Joined
Jan 15, 2009
Messages
58
I have a combo box on a report menu and want to use the value's for other activities. The combo is cmbReports, with (2) fields:

ID Name
1 Red
2 Blue
3 Yellow
4 Green

How would I reference a value of blue, in a "if" statement situation?

If Me.!cmbReports = "Blue" ................

Getting stuck on this one.

Thanks.
 

June7

AWF VIP
Local time
Yesterday, 16:48
Joined
Mar 9, 2014
Messages
5,470
Why not just reference the ID value?

Reference combobox columns by index. Index begins with 0. So:
Me.cmbReports.Column(1) = "Blue"

Don't use both . and !.

Name is a reserved and should not use reserved words as names for anything.
 

Smokeeater

Registered User.
Local time
Yesterday, 20:48
Joined
Jan 15, 2009
Messages
58
June7 - thank you very much for your quick reply. That is what I needed.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:48
Joined
Feb 19, 2002
Messages
43,257
Although June gave you the syntax you asked for, I would be cautious of referencing the text value in code since someone could have changed that and if that happens, your code will not work correctly and you might not notice for a while. I realize that the code looks more confusing if you reference 123 rather than Blue so just add a comment so that people don't have to look up what 123 means.
 

Smokeeater

Registered User.
Local time
Yesterday, 20:48
Joined
Jan 15, 2009
Messages
58
Thanks Pat. I will keep that in mind when developing the code.
 

Users who are viewing this thread

Top Bottom