You need to tackle this at two stages; firstly when the user first navigates
to each record on the form, secondly when they update the control bound to
the 'Yes or No' field. It also makes a difference whether the user moves to
an empty new record or to an existing one.
To cater for when the user moves to a record put code in the form's Current
event procedure. For this example I'll assume the 'Yes or No' field is
called MyYesNo and the field in which data is to be entered if Yes is
answered is called MyYesText, and if No is answered is called MyNoText. So
the Current event procedure's code would go like this:
' first determine if the user has moved to a
' new or existing record
If Me.NewRecord Then
' in the case of a new record disable both text boxes
' until user selects 'yes' or 'no'
Me.[MyYesText].Enabled = False
Me.[MyNoText].Enabled = False
Else
' if its an existing record disable the relevant
' control(s) on the basis of the value of MyYesNo
Me.[MyYesText].Enabled = (Nz([MyYesNo],"No") = "Yes")
Me.[MyNoText].Enabled = (Nz([MyYesNo],"Yes") = "No")
EndIf
The code in the AfterUpdate event procedure of the MyYesNo control is the
same as that in the last part of the above, but you also have to cater for a
user changing their mind, e.g. answering 'yes' and entering something in
MyYesText, then going back and answering 'no', or vice versa, so you need to
delete (set to Null) what they might have already entered in either. You
also need to allow for the possibility, albeit a remote one, of a user
setting the combo box to Null, in which case both text boxes should be
disabled until they select 'yes' or 'no'. You can use the Nz function to
return "Yes" or "No" if the combo box is Null, thus forcing the expression to
evaluate to False and disable the text box. So the code would be:
Me.[MyYesText] = Null
Me.[MyNoText] = Null
Me.[MyYesText].Enabled = (Nz([MyYesNo],"No") = "Yes")
Me.[MyNoText].Enabled = (Nz([MyYesNo],"Yes") = "No")
Ken Sheridan
Stafford, England