views:

230

answers:

3

I have a series of "on Change" Enabled/Disabled subroutines in the VBA for a form.

When scrolling through the form to view records however, only the main routine runs--the subroutines don't. As a result, questions appear disbaled that have responses displayed.

How do I get the subroutines to run when a record is viewed/changed?

A: 

The OnChange only fires when the relevant object is updated. If you want code to run whenever the record is scrolled, put it in the form's OnCurrent event.

Larry Lustig
A: 

I too have found Access form events to be a bit hard to work with/unpredictable. One thing that worked for me is to use a label or textbox and set the Control Source to a formula or a call to my own VBA function to get what I need done. Your control could also be invisible if it is not needed for the GUI. I doubt this is best practice but this "simulated" event worked for me.

Sam Russo
I too found the Access form and control events to be a bit tricky when I first started working with Access. But now I generally only use about 3 or 4 of them and I like to think my apps run quite smoothly.
Tony Toews
I try use standard events whenever they work but I used the ControlSource trick in a continuous form since as David mentioned above, the scrolling record events were not working out.
Sam Russo
A: 

If you need conditional presentation in a list, a continuous form and events are not going to do the job. In some cases CONDITIONAL FORMATTING will do the job, but only for appearance -- it can't do things like show/hide controls or alter the rowsource of dropdown lists or requery them.

Conceptually it would be impossible to do so. Form-level events fire for the record. Scrolling through the form does not move the record pointer.

I avoid using continuous forms for editing precisely because of this issue. Instead, I bind a detail subform to the PK value of the record selected in the continuous form, and then the detail form can do all the conditional formatting it needs to.

David-W-Fenton