Enable/disable fields

  • Thread starter RipperT \(again\)
  • Start date
R

RipperT \(again\)

Private Sub Form Current()
If [nameofcontrolwithvalue] = "the value" Then

[othercontrol].Enable = False 'Disable other
control

Else

[othercontrol].Enable = True 'Enable other
control

End If

End Sub

I am wondering what the syntax would be if I wanted "the
value" to be multiple values, in other words, the field
in question could accept any of 3 or 4 pre-determined
values. Is this possible?

Rip
 
A

Allen Browne

Private Sub Form Current()
Dim bEnabled As Boolean

If (Me.[nameofcontrolwithvalue] = 1) OR (Me.[nameofcontrolwithvalue] =
3) Then
bEnabled = True
End If

Me.[othercontrol].Enabled = bEnabled
End Sub


Add more OR phrases if needed.
 
D

Dirk Goldgar

RipperT (again) said:
Private Sub Form Current()
If [nameofcontrolwithvalue] = "the value" Then

[othercontrol].Enable = False 'Disable other
control

Else

[othercontrol].Enable = True 'Enable other
control

End If

End Sub

I am wondering what the syntax would be if I wanted "the
value" to be multiple values, in other words, the field
in question could accept any of 3 or 4 pre-determined
values. Is this possible?

Rip

You *could* use multiple conditional clauses connected with the "Or"
conjunction:

If (this is true) _
Or (that is true) _
Or (the other is true) _
Then
' do A
Else
' do B
End If

However, in any case where you want to check for alternate values for
the same expression, there's a simpler way: use a Select Case
statement. Like this:

Select Case Me.[nameofcontrolwithvalue]
Case "one value", "another value", "yet another value"
Me.[othercontrol].Enabled = False
Case Else

Me.[othercontrol].Enabled = True
End Select
 

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