Preventing data in remaining fields if first field has value of 'N

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form in which the first field in the 'Detail' section asks if a
certain test was performed. If it was, then the rest of the fields on the
form will house the results from that test. If it was not performed, then I
obviously don't want any data in the remaining fields.

Does anyone have any code examples where I can 'grey out' (utilitzing 'On
Lost Focus' Field Property perhaps?) the remaining fields on the form if this
first field has a value of 'No' (and, conversely have the fields NOT be
greyed out if the first field has a value of 'Yes')?

I suppose I could use the Validation Rule in the underlying table, but it
seems a bit clumsy to have to do that for each and every remaining field. I
know Access pretty well, but am a novice in code, so any examples would be
most helpful.

Thank you!
 
I would use code in two events: the form's Current event, and the textbox's
AfterUpdate event. Both events should disable/enable the other fields in the
record based on the value that in the textbox.

Example:

Private Sub Form_Current()
Dim blnEnable As Boolean
blnEnable = (Me.Ntextbox.Value <> "N")
Me.ControlName1.Enabled = blnEnable
Me.ControlName2.Enabled = blnEnable
End Sub


Private Sub Ntextbox_AfterUpdate()
Dim blnEnable As Boolean
blnEnable = (Me.Ntextbox.Value <> "N")
Me.ControlName1.Enabled = blnEnable
Me.ControlName2.Enabled = blnEnable
End Sub
 
Ken,

Aces on your code! I tweaked it a bit for my application and it works like
a charm-- thanks!
 
You're welcome.

--

Ken Snell
<MS ACCESS MVP>

Pat Dools said:
Ken,

Aces on your code! I tweaked it a bit for my application and it works like
a charm-- thanks!
 
Back
Top