Milewskp
asked on
How to save changes to a record when form doesn't have the focus
I use Docmd.RunCommand acCmdSaveRecord to save the user's changes to the current record of a form, but this requires settting the focus to that form/ subform.
Is there a way to save the users' changes to the current record of a form witout moving focus to that form (say, when they have two forms open)?
Is there a way to save the users' changes to the current record of a form witout moving focus to that form (say, when they have two forms open)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or
Form_YourFormName.Dirty = False
mx
Form_YourFormName.Dirty = False
mx
ASKER
Hi Jim,
Forms![<myformname>].Dirty = False worked great. Thanks!
Forms![<myformname>].Dirty
<<Forms![<myformname>].Dir ty = False worked great. Thanks! >>
I never think of this because really it's an un-documented way of saving a record. I know a lot of developers use it without issue, but I know it doesn't work quite the same way as using a save command.
When I had updated my framework code to use it, I ran into problems and had to go back to saving records with a save cmd. Don't remember getting to the bottom of what the difference was, but I had gotten some weird situations/errors.
JimD.
I never think of this because really it's an un-documented way of saving a record. I know a lot of developers use it without issue, but I know it doesn't work quite the same way as using a save command.
When I had updated my framework code to use it, I ran into problems and had to go back to saving records with a save cmd. Don't remember getting to the bottom of what the difference was, but I had gotten some weird situations/errors.
JimD.
ASKER
Hi Jim,
Thanks for the heads up.
Thanks for the heads up.
"but I know it doesn't work quite the same way as using a save command."
Right. I works considerably better and more consistently. Also note that the method I posted will give you intellisense when you type the Dot after the Form name.
mx
Right. I works considerably better and more consistently. Also note that the method I posted will give you intellisense when you type the Dot after the Form name.
mx
<<Right. I works considerably better and more consistently.>>
In what way?
JimD.
In what way?
JimD.
Because sometimes Docmd.RunCommand acCmdSaveRecord will error out saying 'that command is not available now ..." ... whereas Me.Dirty = False *willl* not error and *will* save the record.
mx
mx
So there must be some timing issues at work then with event firing. That's probably why I saw spurious errors when I set Me.Dirty = False. Record for some reason was not ready to be saved.
As I said, I didn't track it down because I didn't have a lot of time to spend on it. This is one of those things that can suck up a lot of time and you don’t usually end up with an answer anyway. So I went back to using DoCmd fairly quickly and it straightened it out.
JimD.
I have never ever had an issue with Me.Dirty = False, but I certainly have the the DoCmd version.
mx
mx
Nope.
JimD.