search key not found - but only when saving via button

Dear experts -
This is a little puzzling. I have a form. In the 'Save' button, i have, simply:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Now, if I save the record by pressing Shift Enter - it saves normally and gives no message.

However, if I save by pressing the above button, it also behaves properly BUT gives me the error message NO CURRENT RECORD. (if I am turning on the error trapping, it gives the message: "search key not found".

any idea what would cause this (data seem fine - I don't think there is any problem with the data) and does the message mean anything and if not, can I trap for it?
Who is Participating?
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
You should not use that to save a record. Instead use either:

If Me.Dirty Then Me.Dirty = False


DoCmd.RunCommand acCmdSaveRecord

"DoMenuItem" has was replaced in Access 97 by the RunCommand method. DoMenuItem is included only to provide backwards compatibility. According to the MSDN article on DoMenuItem:

Some commands from previous versions of Microsoft Access aren't available in Microsoft Access 2000, and DoMenuItem methods that run these commands will cause an error when they're executed in Visual Basic. You must edit your Visual Basic code to replace or delete occurrences of such DoMenuItem methods.

This would apply to versions of Access AFTER 2000 as well, so take care when using these old commands.
Jeffrey CoachmanMIS LiasonCommented:
<No Points wanted>

Even if you look at this purely from a lazy man's standpoint, it is much easier to type (and remember:
    If Me.Dirty Then Me.Dirty = False
...than it is to type/remember:
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70


terpsichoreAuthor Commented:
thanks - and thanks to mr. coachman as well.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.