Is this the best way to save a record in a looooooong form?

DAZarlengo

New Member
Joined
Oct 18, 2003
Messages
11
We use a form to input a very long record. Several of the fields involve a lot of typing. The problem is that if anything interrupts the input process (such as hitting escape, a power glitch, etc.), the entire record is lost, since Access only saves a record when you finish the last field.

We would like the record to be automatically saved numerous times along the way, without advancing to the next record.

I found one method that works perfectly.

* Open the form in design mode
* Right-click each text box we want to save at
* Click Properties
* Click the box for “On Got Focus”
* Click the down arrow and select [Event Procedure]
* Click the little box with 3 dots

This creates a bit of VB code attached to the form that looks like:

Private Sub MyControlName_GotFocus()
End Sub

I insert one more line, to end up with this:

Private Sub MyControlName_GotFocus()
RunCommand acCmdSaveRecord
End Sub

This works perfectly. What I don’t like about it is that each control requires a different sub, with the control name as part of the Sub statement. What I would like to do is just write one Sub, and have the “On Got Focus” from any text box execute it.

To sum up the problem, how do I make any of the event procedures, such as "On Got Focus," call a user-written Sub?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Re: Is this the best way to save a record in a looooooong fo

You still need to have code for each control, using Got Focus or whatever.
The trick is to create the DoCmd.Save... command in a Function procedure in a standard module.
Call it Function SaveRecord(), and call the Module something else like modUtility.

Then you can use a call to modUtility.SaveRecord in each GotFocus event. Advantage: If you decide to do something else you only have to edit one procedure and it is implemented everywhere.

Denis
 
Upvote 0
I have not played with it but you may be able to trap the KeyDown event for the Enter and Tab keys and fire the code that way.

HTH

Peter
 
Upvote 0

Forum statistics

Threads
1,221,575
Messages
6,160,603
Members
451,657
Latest member
Ang24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top