By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 IT Pros & Developers. It's quick & easy.

How do I use equal to or less then in VB

100+
P: 147
I am trying to the following but it stops priot to completion:

Expand|Select|Wrap|Line Numbers
  1. ......
  2. Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank < 1
  3. stRateOfPay = "Ptlm1"
  4. Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank > 1 = 2 < 3
  5. stRateOfPay = "Ptlm2"
  6. ..........
  7.  
At line 3 it checks that Forms!frmOverTime!YearsInRank is greater then 1 and stops there and fils the dtat under line 4 in my form. It is not continuing to check if it is equal to 2 and less then 3 and continuing on if it is. What am I doing wrong?????

Thanks
Jan 20 '09 #1
Share this Question
Share on Google+
12 Replies


Expert 100+
P: 1,287
I think you are using the Case incorrectly. You can have

Select Case rs!Rank
Is = 6 'or "6" for text
Select Case Forms!frmOverTime!YearsInRank 'or just use If
etc.

Each clause in the case statement is going to compare to whatever you Select. Pretty sure you can't combine them with AND.
Jan 20 '09 #2

100+
P: 147
It actually looks like this:


Expand|Select|Wrap|Line Numbers
  1. Select Case True
  2. Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank < 1
  3. stRateOfPay = "Ptlm1"
  4. Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank > 1 = 2 < 3
  5. stRateOfPay = "Ptlm2"
  6.  
Any ideas?
Jan 20 '09 #3

Expert 100+
P: 1,287
Let me try that again with code tags.

Expand|Select|Wrap|Line Numbers
  1. Select Case rs!Rank
  2.     Is = 6 'or "6" for text
  3.         Select Case Forms!frmOverTime!YearsInRank 'or just use If
  4.     etc.
Sorry I hit TAB the first time and posted prematurely.
Jan 20 '09 #4

100+
P: 147
My problem is with the comparison at the end it s not fully checking the value of Forms!frmOverTime!YearsInRank to se if it is less than 1 or equal or greater than 2 but less than 3.
Jan 20 '09 #5

Expert 100+
P: 1,287
You might be able to put And Forms!frmOverTime!YearsInRank in between each of those, or just write an if statement. The syntax is just wrong. I've never used Select Case True. Is that a common practice?
Jan 20 '09 #6

100+
P: 147
I have no idea, I was using elseIf but someone else pointed me to use select case.
Jan 20 '09 #7

Expert 100+
P: 1,287
Actually, why would you say "greater than 1 and equal to 2 and less than 3" instead of simply "equal to 2"?
Jan 20 '09 #8

100+
P: 147
good point I was using months before and canned that idea. I am movving on to another angle.

Thanks
Jan 20 '09 #9

NeoPa
Expert Mod 15k+
P: 31,494
@ChipR
No Chip.

It is however very flexible and powerful ;)

Select Case is a very flexible and clear way of splitting the logic. It can handle multiple splits more clearly than multiple Ifs or even ElseIfs.

What can sometimes be a limitation is that the checks are not always done on the same items, even when the splitting of the logic all happens in one place. This is where the Select Case True comes in.

Think about it. The first of the Case statements to resolve to True will be selected when run. Elegant and supremely flexible.

Dan's code was actually quite valid (in its concept at least).
Jan 26 '09 #10

NeoPa
Expert Mod 15k+
P: 31,494
@DAHMB
I'm assuming you're talking about your line #4 here?

Can you say exactly what you're looking for in Forms!frmOverTime!YearsInRank? Can we also assume that this figure will be integral (whole numbers only)?
Jan 26 '09 #11

P: 10
In Line 4, do all of those conditions need to be true? PErhaps you need to break that up with an AND or an OR

Forms!frmOverTime!YearsInRank > 1 AND/OR Forms!frmOverTime!YearsInRank = 2 AND/OR Forms!frmOverTime!YearsInRank < 3

Where AND/OR is either AND or OR. Just a thought.

Steve
Jan 27 '09 #12

NeoPa
Expert Mod 15k+
P: 31,494
Steve's point is very likely to be right for your situation. Clarification of my earlier point would help us to be sure.

Assuming then that it is so for now, this leaves us looking to find a way to reduce all the referencing in Forms!frmOverTime!YearsInRank.

Would this code be running within the frmOverTime module anyway by any chance? If so, then Me.YearsInRank (or even more simply YearsInRank alone) would be a simpler and shorter way of referring to the same object.
Jan 27 '09 #13

Post your reply

Sign in to post your reply or Sign up for a free account.