What is the error you get? Did you confirm that acCmdSaveRecord is a valid constant?
Error in VBA from DoCmd.RunCommand acCmdSaveRecord
We have moved to Access 2016 but are using databases created in Access 2003. We get an error when the VBA gets to the command:
DoCmd.RunCommand acCmdSaveRecord
So far, everything else seems to work okay.
Note: some of our computers are running Windows 7, Others are running Windows 10.
Why won't this command work? Is there a rational work-around?
Thanks
Microsoft 365 and Office | Access | For home | Windows
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
17 additional answers
Sort by: Most helpful
-
Anonymous
2020-01-21T02:54:21+00:00 Thanks, I'll try it tomorrow.
-
Anonymous
2020-01-21T13:46:32+00:00 If you have time to make a database to illustrate it, that would be helpful so we can address any underlying issue, but I understand if you don't have time.
Is it possible that before executing the command, the focus has moved somewhere such that the command really isn't available? For example, to some other document window that doesn't have a dirty record?
That would explain why setting Me.Dirty = False might still work, since it always acts on the form running the event, and is not sensitive to where the focus is.
-
Anonymous
2020-01-22T06:26:14+00:00 Actually, Tom's idea of using the Me.Dirty property is good, except that as these posters state here:
'----------------------------------------------------------------------
You can't simply assign true [or false] to Me.Dirty, because Me.Dirty is a read-only variable. The command DoCmd.RunCommand acCmdSaveRecord can only be executed if the Form is dirty. So what i always do is this:
If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord End If'----------------------------------------------------------------------
The original poster in that thread mentioned that he put in a "Me.Refresh" command before the save command, and his error stopped occurring.
See if these suggestions work...
-
Tom van Stiphout 40,096 Reputation points MVP Volunteer Moderator
2020-01-22T13:34:01+00:00 Not exactly, Al.
See https://docs.microsoft.com/en-us/office/vba/api/Access.Form.Dirty(property):
You can use the Dirty property to determine whether the current record has been modified since it was last saved. Read/write Boolean.