enabling ctrls on check not behaving as expected

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

Guest

I'm trying to enable a textbox and a subform upon a checkbox being checked.
The checkbox defaults to no and other 2 ctrls default to disabled upon form
startup.

I would like the "disabled" state to reset for new records. Right now, if I
check the box and enter data in my 2 ctrls for record 1, when I move to
record 2, the "enabled" states carry over, even though the checkbox is
cleared. Conversely, if I go to record 2 and click on the checkbox twice, I
get the ctrls disabled, but when I move back to record one, even though I
have entered data into the disabled forms and the checkbox remains checked,
the 2 ctrls carry over the disabled state from record 2

I have this code ...

Private Sub extension_AfterUpdate()

Me.num_yrs_prev_funded.Enabled = (Me.extension.Value = True)
Me.IRAD_targeted_programs_subform.Enabled = (Me.extension.Value = True)

End Sub

where num_yrs_prev_funded is the textbox and the other one is obviously the
subform. Extension is the checkbox.

I hope this is clear, but in a nutshell, if a record has been entered and
the checkbox checked, I need the controls to always be enabled. In the case
that the checkbox is not checked (such as a new record especially) I always
want the 2 controls to be disabled?

Am I missing something basic?
Thanks in advance
Keith
 
I seem to get the functionality I need when keeping the same code in After
Update but also replicating it in On Enter. So, I think the problem is
solved. My follow up question, I guess, is why?

Thanks,
Keith
 
You do need that code in two places. The Check box's
AfterUpdate is one. But the other place is the Form's
Current event, not a control's enter or exit event. The
Current event will check the state of the check box field as
you move to each record in the form.
 
Marshall,

Thanks for the reply. While I seemed to be getting the correct functionality
with the solution I listed before, I moved the code over to the form's
current event (and confirmed that I still get the functionality that I need).

Since I'm new at the coding piece of Access, there's no way I'm not
deferring to your expertise! Thanks for the help.

Keith

Marshall Barton said:
You do need that code in two places. The Check box's
AfterUpdate is one. But the other place is the Form's
Current event, not a control's enter or exit event. The
Current event will check the state of the check box field as
you move to each record in the form.
--
Marsh
MVP [MS Access]


Keith McCarron said:
I seem to get the functionality I need when keeping the same code in After
Update but also replicating it in On Enter. So, I think the problem is
solved. My follow up question, I guess, is why?
 
Using a control's Enter event only works if you click or tab
into the control. You may have the control first in the
form's Tab Order so this often(?) happens as you move to
each record, otherwise, if you have moved the focus to some
other control and navigate to another record, it will not
trigger the event. The Exit event would be a little more
problematic.

OTOH, the Form's Current event is always triggered when you
navigate to a different record, regardless of the control
that has the focus.
 
Back
Top