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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I check Multiple ID's

Status
Not open for further replies.

cneill

Instructor
Mar 18, 2003
210
GB
Hi,

Can you tel me where I am going wrong with this code

Private Sub

Dim SchemeID As String

SchemeID = Me.SchemeID

If SchemeID = 1 Then
...Do something
End If

End Sub

This works fine and the following does not

Private Sub

Dim SchemeID As String

SchemeID = Me.SchemeID

If SchemeID = 1 or 2 or 3 or 4 Then
...Do something
End If

End Sub

can anyone help me on this?
I want it to be able to check many ID's in a single if statement if possible.
Thanks Neill

 
You haven't told us what's "not working", and you have mixed pseudo-code with real code, so I can't tell if you've written bad code or not.

However, if this is from your real code:

Code:
If SchemeID = 1 or 2 or 3 or 4 Then

Then that's invalid. You would need:
Code:
If SchemeID = 1 or SchemeID = 2 or SchemeID = 3 or Scheme = 4 Then

or if it's always in a sequence like that, this would suffice
Code:
If SchemeID >= 1 And SchemeID <= 4 Then

I suggest you use Option Explicit in your VBA code environment so that invalid code like the first line is discovered quickly.
 
You can also look at a Select case statement

Select Case me.schemeID
Case 1
Bonus = salary * 0.1
Case 2, 3
Bonus = salary * 0.09
Case 4 To 6
Bonus = salary * 0.07
Case Is > 8
Bonus = 100
Case Else
Bonus = 0
End Select
 
MajP

Select Case statement worked a treat, many thanks

Neill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top