Enable/disable fields

  • Thread starter Thread starter RipperT \(again\)
  • Start date 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
 
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.
 
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
 
Back
Top