IF statement help

CBG2112

Registered User.
Local time
Today, 03:19
Joined
Aug 4, 2009
Messages
32
I have several consoles listed in a table. When the user selects either a PS3, XBOX, or WII, the NEWGEN checkbox will be automatically marked. I would like to use one IF statement instead of three separate ones. Thanks in advance.

Code:
 If txtCONSOLE.Text = "PS3", "XBOX", OR "WII" Then
 NEWGEN_FL.Value = -1
 
I have several consoles listed in a table. When the user selects either a PS3, XBOX, or WII, the NEWGEN checkbox will be automatically marked. I would like to use one IF statement instead of three separate ones. Thanks in advance.

Code:
 If txtCONSOLE.Text = "PS3", "XBOX", OR "WII" Then
 NEWGEN_FL.Value = -1

Try this:

Code:
If txtConsole = "PS3" or txtConsole = "XBOX" or txtConsole = "WII" Then
NEWGEN_FL.Value = -1
End If
 
Thanks. It worked.
 
Or a simpler one:
Code:
If txtCONSOLE [COLOR=red][B]In([/B][/COLOR]"PS3", "XBOX", "WII"[B][COLOR=red])[/COLOR][/B] Then

Also, unless absolutely necessary do NOT use .TEXT as that requires that the control have focus. You will need it if you use the Change event of the control but other than that most of the time you would use .VALUE instead and since it is the default for most controls you don't even need to include it.
 
I tried using the code you listed but it gives me a syntax error. Your suggestion regarding the .TEXT and .VALUE is very helpful.Thanks!
 
I tried using the code you listed but it gives me a syntax error. Your suggestion regarding the .TEXT and .VALUE is very helpful.Thanks!

Sorry, I got mixed up a bit. You can't use it like that in VBA. What you can use is a Select Case:

Code:
Select Case Me.txtConsole
Case "PS3", "XBOX", "WII"
[COLOR=#ff0000][/COLOR][COLOR=black] Do whatever here[/COLOR]
[COLOR=black]Case Else[/COLOR]
[COLOR=black]   Do an alternate here[/COLOR]
[COLOR=black]End Select[/COLOR]

So, if you have a few things you can just use the same code Kryst51 gave. If you have more items then it gets a bit more unwieldy and so the Select Case would work.
 

Users who are viewing this thread

Back
Top Bottom