How to run event on other options

  • Thread starter Thread starter Mommybear
  • Start date Start date
M

Mommybear

I created a data entry form with a Save button. This button runs thru a
procedure event which moves data to the proper fields, does a nested
if-then-else statement and other things. I understand that when you tab to
the last field, enter your data, then tab again or press enter, the new
record is automatically written to my database. However, this does not run
thru the code on my Save button. What is the easiest way to run this code.
I can add it to the event for enter and Tab functions, or is there a way to
tell it to run the Save_command procedure event. Also, what command do I
want to use to put the screen back to blank and ready for the next new record.
 
I created a data entry form with a Save button. This button runs thru a
procedure event which moves data to the proper fields, does a nested
if-then-else statement and other things. I understand that when you tab to
the last field, enter your data, then tab again or press enter, the new
record is automatically written to my database. However, this does not run
thru the code on my Save button. What is the easiest way to run this code.
I can add it to the event for enter and Tab functions, or is there a way to
tell it to run the Save_command procedure event. Also, what command do I
want to use to put the screen back to blank and ready for the next new record.

So I take it this is an unbound form (nothing in the textboxes' Control
Source) and that you've explicitly overridden the default form behavior in
exchange for doing it all in code? That's certainly doable but it's the hard
way!

To force a save to disk from a *bound* form all you need is your choice of
either:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord acForm, Me.Name, acNewRecord

or

If Me.Dirty Then Me.Dirty = False
DoCmd.GoToRecord acForm, Me.Name, acNewRecord

If the form is in fact unbound, you must parse out each field individually,
write it into the appropriate table record, and then explicitly set each field
to NULL. Doable but lots more work!
 
The fields in the form are bound, however, I have other fields that are not
on the form that default to a value, are calculated, being formatted to write
all caps, or go thru an if statement to determine value that are being
populated thru this Event procedure. The save button works great, however, I
don't know what is best in terms of handling the autosave when you tab or
enter past the last field on the screen. Do I duplicate the code or is there
a command that I could use to force this thru the save button code.
 
The fields in the form are bound, however, I have other fields that are not
on the form that default to a value, are calculated, being formatted to write
all caps, or go thru an if statement to determine value that are being
populated thru this Event procedure. The save button works great, however, I
don't know what is best in terms of handling the autosave when you tab or
enter past the last field on the screen. Do I duplicate the code or is there
a command that I could use to force this thru the save button code.

I'm not absolutely sure what is going on here - it sounds like you're
(unwisely) storing derived or calculated data?

In any case, the Form's BeforeUpdate event fires whenever and however it
completes a record and starts to write it to disk. You might want to move your
code from the button event to the BeforeUpdate event (which will be triggered
when your Save button does its thing).
 
I have a database that has about 39 fields in it. Only about 20 of them are
actually entered. The others are either a default value, or a value based on
what is entered in specific fields such as:
box a = contractor box b =vendor, value stored = 1
box a = contractor box b = contractor, value stored = 2
This database consists of 30k records therefore, I can not change the way it
works, only make it simple to add to.
I figured out that all I needed to do was to add a Call to the on exit
event. This works wonderfully for what I need. Thank you.
 
Back
Top