Reputation: 3
I have an Access database with several fields that are check boxes that correspond to other fields such as an ID# and date. I want these fields to be grayed out when the corresponding check box is not selected and to open up when selected.
Check box: Study
Field 1: StudyID
Fields 2: StudyDate
The 2 fields have been disabled for default. I am using the following code for AfterUpdate
on the checkbox:
If Me.Study Then
StudyID.Enabled = True
StudyDate.Enabled = True
Else
StudyID.Enabled = False
StudyDate.Enabled = False
End If
This makes it sort of work. It works on action when you click but it doesn't save the change when you switch records or close/reopen the form. Is this the right code, or is there something better, or does each record need to be individually linked?
Upvotes: 0
Views: 1485
Reputation: 381
What you're missing is that the code needs to run again "On Current". That way every time you change back to the form, it will look to see if the checkbox is checked, and enable/disable the fields correctly.
Select the form (click the little square at top left where the rulers intersect), then on the Event properties tab click "On Current". Load this code:
If Me.Study = -1 Then
StudyID.Enabled = True
studydate.Enabled = True
Else
StudyID.Enabled = False
studydate.Enabled = False
End If
Upvotes: 1