Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple conditions in IF statement 1

Status
Not open for further replies.

MDJ52

MIS
Mar 30, 2001
120
US
I am trying to use multiple variables in an IF statement. The one that works is:
******************************************************
If my1!CustPParm1 = Me.combo1.Caption And my1!CustPQualifier1 <> Me.combo1 Then
******************************************************
This works as long as there is only one parameter to compare for each part of the IF statement.

What I would like to try to do is come up with multiple variables in the second part of the IF statement.
******************************************************
If my1!CustPParm1 = Me.combo1.Caption And ((Me.combo1 <> "crank1") Or (Me.combo1 <> "crank2")) Then
******************************************************
I get an error on this IF statement. I can capture the 2 parameters, Crank1 and Crank2 to replace my1!CustPQualifier1 from another screen. How can I tell the IF statement to use 2 parameters to compare to Me.combo1 ??? I also tried the 'IN' function to put them into brackets. This also did not work unless my format was just messed up.
Thanks for your help
Mike

 
The code looks ok, what error are you getting? The "in" should also work, but you have to be sure to use "not" before the expression.

not( me.combo1 in ("crank1", "crank2"))
 
The "in" should also work
In VBA ???
You have to use the Eval function for such syntax.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
stix4t2,
I tried your code for the IN function. It continues to come back looking for a ')' in place of the IN parameter.
Any other thoughts?
Mike
 
MDJ52, why not say us which error you get with your original post ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The error I get with the original attempt is the fact that the IF statement does not work. Even if Combo1 has the 1 of the 2 parameters it still runs the code. I also tried:

chkno = Eval("me.combo1 in ('handcrank','bevelcrank')")

This should give me a -1 for chkno if I select either of the 2 parameters. What I get is an error of 'unknown function'. Since after typing in the statement it does not capitalize 'in', I am betting that is where my error is at.
What reference do I need to use 'in'?

Any new thoughts?
Mike
 
So, you simply had a logic problem ?
If my1!CustPParm1 = Me.combo1.Caption And Me.combo1 <> "crank1" And Me.combo1 <> "crank2" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
your solution worked. This would be considerably easier however if I could populate what me.combo1 should not be equal to from a text box with multiple parameters in it i.e 'crank1','crank2'. I could then use this in an 'IN' statement.
What reference is necessary to use the 'IN' statement.
Thanks,
Mike

 
Say TextBox1="crank1,crank2,crank3"
You may try something like this:
If my1!CustPParm1 = Me.combo1.Caption And InStr(1, "," & Me.TextBox1 & ",", "," & Me.combo1 & ",", 1) = 0 Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
You hit it with the InStr function. I have never used it before, but it worked like a champ. I populated my1!CustPQualifier1 with Crank1,Crank2.
I then used

If my1!CustPParm1 = Me.Combo1Label.Caption And InStr(1, my1!CustPQualifier1, Me.Combo1, 1) = 0 Then

It was able to interpret it without building a group of strings as you had in yours, but it sent me in the right direction.
Worked Great
A star for you

Thanks, Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top