Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to save changes to a record when form doesn't have the focus

Posted on 2011-04-28
11
Medium Priority
?
374 Views
Last Modified: 2013-11-28
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)?
0
Comment
Question by:Milewskp
  • 5
  • 4
  • 2
11 Comments
 
LVL 59
ID: 35487677

  Nope.

JimD.
0
 
LVL 59

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 35487685
Actually, I might have to take that back.  I always forget about that Dirty property.  Try:

 Forms![<myformname>].Dirty = False

JimD.
0
 
LVL 75
ID: 35487720
Or

Form_YourFormName.Dirty = False

mx
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:Milewskp
ID: 35491022
Hi Jim,
Forms![<myformname>].Dirty = False worked great. Thanks!
0
 
LVL 59
ID: 35491302
<<Forms![<myformname>].Dirty = 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.
0
 
LVL 1

Author Comment

by:Milewskp
ID: 35491413
Hi Jim,
Thanks for the heads up.
0
 
LVL 75
ID: 35492832
"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
0
 
LVL 59
ID: 35494148
<<Right. I works considerably better and more consistently.>>

  In what way?

JimD.
0
 
LVL 75
ID: 35494189
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
0
 
LVL 59
ID: 35494466

  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.
0
 
LVL 75
ID: 35494493
I have never ever had an issue with Me.Dirty = False, but I certainly have the the DoCmd version.

mx
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question