AfterUpdate

  • Thread starter Thread starter Ivor Williams
  • Start date Start date
I

Ivor Williams

Is there a way in a subform whose default view is either Datatsheet or
Continuous Form to change the state of a control in a single record based on
the state of another control in the same record? For example, if the subform
has the fields chkA and txtB, if chkA is true, enable txtB, if chkA is
false, disable txtB. If the following code:

Private Sub chkA_AfterUpdate()
If chkA.Value = -1 Then txtB.Enabled = True Else If chkA.Value = 0 Then
txtB.Enabled = False
End Sub

is used, regardless of which record has the focus, the state of txtB will
change in every record whenever chkA is changed.
Please let me know if I've not explained myself clearly.

Ivor
 
Hi Ivor,

In a continuous form (or datasheet) each "instance" of a control will have
the same state. However, only one will be active at any time - the one in
the current record. It can make your form look wrong, but that's
unavoidable.

You need to put the code into the subform's Current event, so that the
enabled state is set for the current record, and changes whenever you change
record. If you need it to happen when the records is edited (ie. when chkA
is changed for the current record), you'll need to retain the code in the
chkA_AfterUpdate event also.

Note that you can simplify the code to:
txtB.Enabled = chkA
since chkA is already a boolean value.

HTH,

Rob
 
You might also take a look at conditional formating. Although it will
not function for check boxes, it does work quite well for txtboxes,
etc. With the conditional formating, it is record specific when in
datasheet view.
 
Back
Top