question about command to save record (1 Viewer)

moradisndat

Registered User.
Local time
Today, 15:14
Joined
Mar 27, 2015
Messages
14
I've been looking at 2 lines of code in 2 different modules and it looks like they both do the same thing. Can someone tell me if there is any difference between these 2 lines of code?

DoCmd.RunCommand acCmdSaveRecord

versus

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:14
Joined
Feb 19, 2013
Messages
16,668
both work, but the second only relates to 2003 and earlier - effectively it is running the save action in the access menu bar.

Personally I would stick with the first one
 

moradisndat

Registered User.
Local time
Today, 15:14
Joined
Mar 27, 2015
Messages
14
Thanks for explaining the difference and for your quick reply.
 

Orthodox Dave

Home Developer
Local time
Today, 23:14
Joined
Apr 13, 2017
Messages
218
DoCmd.RunCommand acCmdSaveRecord only works with the Current record. If you are updating data in a different form from the one you are in, you can do this by temporarily re-setting the focus to the other form - thus making it the current record.

Here's one I did earlier. In this example, we are updating a field in the FA02_Trans_Header form, but doing it from the FR21_MailTextType form. Just showing the relevant bit of code:

Code:
Forms!FA02_Trans_Header.SetFocus
Forms!FA02_Trans_Header!Subject = SubjectText
DoCmd.RunCommand acCmdSaveRecord
Forms!FR21_MailTextType.SetFocus
 
Last edited:

missinglinq

AWF VIP
Local time
Today, 18:14
Joined
Jun 20, 2003
Messages
6,423
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

was actually used by the Command Button Wizard, up through v2003, but its use has been deprecated since then, the fear/feeling being that MS will eventually stop supporting it, although it still works, as far as I know, and definitely works thru v2007.

DoCmd.RunCommand acCmdSaveRecord

or its brother code

If Me.Dirty Then Me.Dirty = False

are definitely the more preferred approaches.

Linq ;0)>
 

Users who are viewing this thread

Top Bottom