Enabling fields based on multiple criteria

G

Guest

I am trying to enable / disable fields based off of a combo boxes value .
here is my code. I am trying to enforce that if either "Coach Operator" or
Coach Technician" is chosen then certain fields are enabled ... else ... the
fields are disabled .

Here is my code
Private Sub Position_AfterUpdate()
If Me!Position = "Coach Operator" or "Coach Technician" Then
Me.Conviction_DUI.Enabled = True
Me.Conviction_DUI__Date.Enabled = True
Me.Conviction_DUI_Explain.Enabled = True
Me.Ctl10_Year.Enabled = True

Else
Me.Conviction_DUI.Enabled = False
Me.Conviction_DUI__Date.Enabled = False
Me.Conviction_DUI_Explain.Enabled = False
Me.Ctl10_Year.Enabled = False
' Debug Code - Returns The Value of .Position- MsgBox "Position contains
" & Me.Position

End If
End Sub


thanks guys
 
G

Guest

Try this

Me.Conviction_DUI.Enabled = (Nz(Me!Position,"") = "Coach Operator" or
Nz(Me!Position,"") = "Coach Technician")
Me.Conviction_DUI__Date.Enabled = (Nz(Me!Position,"") = "Coach Operator" or
Nz(Me!Position,"") = "Coach Technician")
Me.Conviction_DUI_Explain.Enabled = (Nz(Me!Position,"") = "Coach Operator"
or Nz(Me!Position,"") = "Coach Technician")
Me.Ctl10_Year.Enabled = (Nz(Me!Position,"") = "Coach Operator" or
Nz(Me!Position,"") = "Coach Technician")

Put the code on the After update event of the combo, and on the OnCurrent
event of the form, if you move between records
 
G

Guest

This is easier to read.

Dim bEnabled as boolean

bEnabled = (NZ(me.Position, "") = "Coach Operator") _
OR (NZ(me.Position, "") = "Coach Technician")
Me.Conviction_DUI.Enabled = bEnabled
Me.Conviction_DUI__Date.Enabled = bEnabled
Me.Conviction_DUI_Explain.Enabled = bEnabled
Me.Ctl10_Year.Enabled = bEnabled

HTH
Dale
 

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