Search code examples
vbams-accessms-access-2016

Enabling/disabling input into certain record's field based on the value of another field, but at the same record


I work with Access 2016 and I'm trying to lock/unlock the fields (Epileptic_activity, Quantifiable_activity and Seizure_aspect) in each record, when "Selection"=No/Yes respectively (I have Yes/No in selection). All that is happening in the subform of big navigation form.

I used this method Enabling/disabling input into certain fields based on the value of another field and it work, but it locks/unlocks all the data displayed in the form. As soon as I check any Selection to Yes, all the records have Epileptic_activity, Quantifiable_activity and Seizure_aspect unlocked.

Here is the code which I used:

Private Sub Selection_AfterUpdate()

Me.Epileptic_activity.Enabled = True

Me.Quantifiable_activity.Enabled = True

Me.Seizure_aspect.Enabled = True

If (Me.Selection = False) Then

    Me.Epileptic_activity.Enabled = False

    Me.Quantifiable_activity.Enabled = False

    Me.Seizure_aspect.Enabled = False

    End If

End Sub

So, I would like to be able to lock/unlock the fields following Selection recordwise, because in one record we could have Selection and the following fields are necessary, but the next record doesn't have Selection="yes" and then I would expect to have 3 following fields locked.

How can I make it work?

thx for any help


Solution

  • You cannot change that, this is how Access works.

    However, you can enable/disable each control individually every time the control gets the focus by checking the Selection value.

    Private Sub Epileptic_activity_Enter()
    
        If Selection.Value = False Then Epileptic_activity.Enabled = False Else Epileptic_activity.Enabled = True
    
        'or simply
    
        Epileptic_activity.Enabled = Selection.Value
    
    End Sub
    

    You will need to do this for all three controls.