By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,221 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,221 IT Pros & Developers. It's quick & easy.

Saving the last value in a sub form

P: 99
I'm in Access 2007. I built a feature that to saves the current list in a sub form to a separate table. It works like this: After entering a list of words in the subform, the user can choose to push a button, and a dialog box appears. The user enters a name into the dialog box to identify the list for later use, presses OK and the list is saved.

In the code, I'm using DoCmd.RunSql on the data in the table, so all the data in the sub form needs to be saved to the underlying table in order for the feature to work properly.

The problem occurs on the last item of data in the sub form. If I enter data into the last field, and I do not hit enter/return, and I go right to pressing the button to save the list, the data in the last field will not get saved because it was not saved to the table.

If I attempt to force a save with something like Docmd.RunCommand acSave, I cause 2 problems: 1) If the user did hit return and the data is saved, calling acSave can produce and error. 2) I only want to save the data in the subform. I do not want to apply acSave to the main form.

I assume I need some code in the feature-button to save the last item in the sub form, but I don't know what it should be. Can anyone tell me how I can correct this feature so the last piece of data in the subform is stored in the underlying table, regardless of if the user pressed enter/return?

Dec 15 '09 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 3,532
If Me.Dirty Then Me.Dirty = False only saves the record if it is unsaved.

DoCmd.RunCommand acCmdSaveRecord can also be used, and doesn't throw an error if the record is already saved.

Thirdly, you could simply move off of the subform, to the main form, before running your other code, and the record would be saved.

BTW, Docmd.RunCommand acCmdSave, which is the actual syntax, not acSave,does not save a record! It saves changes to the design of the form!

Linq ;0)>
Dec 15 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.