Event triggers for forms

G

Guest

I have a form with a set of unbound checkboxes representing dates a building
was in use (can be multiple). I want to use the results from this to fill in
the linking table between 2 tables (buildings and eras). However, I don't
want to have to store all of the values of the checkboxes in one of the
individual tables. I've got the code to do all of this, I'm just not sure
where to trigger it from.

Being the controls are unbound, the Before/After Updates events don't happen
because no record is being updated. I'd like for it to happen when the form
moves to another record, but can't figure out which event this is. The only
other idea I had was for it to happen on the Click event of the checkbox, but
I don't want to have to do that many read/writes to the linking table.

Any ideas? If there's a better way of doing this, I'd appreciate it too.
Thanks!
 
D

Douglas J. Steele

I just tested, and both the BeforeUpdate and AfterUpdate events fire for
unbound checkboxes.

Incidentally, one "trick" is to build a function (not a sub) in the form's
class module, and set the appropriate event for all of the controls to
=FunctionName() (make sure you include the equal sign). You can set the
property for all of the check boxes at once if you select all of them (some
methods for selecting multiple controls is to "lasso" them, or to click on
each one while holding down the shift key). Once you've selected them all,
go to the Property dialog, and type the function call there: it will apply
to all of the selected controls.

In the function, you can determine which check box was just checked by
referring to Me.ActiveControl
 
G

Guest

Does the BeforeInsert event happen if no change to the record is made? (again
unbound checkboxes)

I know the update events for the checkboxes fire, I meant the update for the
form (sorry I wasn't clear there). I would rather not have it updating the
link table everytime a check box is clicked, instead I'd like it to happen
when the form is moved to the next record. That way the user can make all
their decisions before anything is written to the table. Let me know if this
is even possible.

I think there needs to be a "NextRecord" event. :p
 
D

Douglas J. Steele

No, I don't believe either of the Form's Update events fire with unbound
controls.

I'm confused, though. It sounds as though your form is bound, and it's only
the check boxes that aren't bound. You may not be aware that with an unbound
check box on a bound form, checking one check box checks all of them.
 
D

Dirk Goldgar

In
Shaun said:
I have a form with a set of unbound checkboxes representing dates a
building was in use (can be multiple). I want to use the results
from this to fill in the linking table between 2 tables (buildings
and eras). However, I don't want to have to store all of the values
of the checkboxes in one of the individual tables. I've got the code
to do all of this, I'm just not sure where to trigger it from.

Being the controls are unbound, the Before/After Updates events don't
happen because no record is being updated. I'd like for it to happen
when the form moves to another record, but can't figure out which
event this is. The only other idea I had was for it to happen on the
Click event of the checkbox, but I don't want to have to do that many
read/writes to the linking table.

Any ideas? If there's a better way of doing this, I'd appreciate it
too. Thanks!

One thing you could do to force the form's BeforeUpdate event to fire
is, in the AfterUpdate events of all the unbound checkboxes, set some
bound field on the form equal to itself. For example,

'----- start of example code -----
Private Sub Checkbox1_AfterUpdate()

Me!SomeBoundField = Me!SomeBoundField

End Sub
'----- end of example code -----

That should dirty the form without actually changing any value.

Another possibility is that you could just set the form's Dirty property
to True. I don't know whether that would work or not, though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top