if ... then... else is not working correctly

S

Silvio

For some reason the "If Toolbar = 4 Or 10 Or 11 Or 12 Or 13 Then" line does
not work. If I enter only one number (e.g. If Toolbar = 12 then) then it
works fine. What I am doing wrong?


Dim Toolbar As Integer
Toolbar = DLookup("ToolbarID", "qryCurrentUser")
If Toolbar = 4 Or 10 Or 11 Or 12 Or 13 Then
Me.AddCycle.Enabled = False
Me.TxHold.Enabled = False
Me.frmHoldsSub.Enabled = False
Else
Me.AddCycle.Enabled = True
Me.TxHold.Enabled = True
Me.frmHoldsSub.Enabled = True
End If
 
P

Piet Linden

For some reason the "If Toolbar = 4 Or 10 Or 11 Or 12 Or 13 Then" line does
not work. If I enter only one number (e.g. If Toolbar = 12 then) then it
works fine. What I am doing wrong?

Dim Toolbar As Integer
Toolbar = DLookup("ToolbarID", "qryCurrentUser")
If Toolbar = 4 Or 10 Or 11 Or 12 Or 13 Then
    Me.AddCycle.Enabled = False
    Me.TxHold.Enabled = False
    Me.frmHoldsSub.Enabled = False
Else
    Me.AddCycle.Enabled = True
    Me.TxHold.Enabled = True
    Me.frmHoldsSub.Enabled = True
End If

one way around it (because I'm being lazy, I guess) is to use a
different version of IF stuff..

Select Case Toolbar
Case 4,10,11,12,13
Me.AddCycle.Enabled = False
Me.TxHold.Enabled = False
Me.frmHoldsSub.Enabled = False
Case Else
Me.AddCycle.Enabled = True
Me.TxHold.Enabled = True
Me.frmHoldsSub.Enabled = True
End Select
 
L

Linq Adams via AccessMonster.com

The Select Case construct is a good match for this situation.

The reason

If Toolbar = 4 Or 10 Or 11 Or 12 Or 13 Then

doesn't work, however, is that you need to repeat each comparison, including
the

Toolbar =

part, i.e.

If Toolbar = 4 Or Toolbar = 10 Or Toolbar =13 Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top