Problem with the following code : DoCmd.RunCommand acCmdPaste

Gilbert Peeters 1 Reputation point
2021-05-10T03:34:34.127+00:00

I have the following code in MS-Acces VBA, when I click on the button called Paste_Bookmark :

Private Sub Paste_Bookmark_Click()
Me!hdrBookmarkLink.SetFocus
DoCmd.RunCommand acCmdPaste
End Sub

The URL that is currently on the clipboard will be pasted in the field Me!hdrBookmarkLink.
That's ok.

But when I want to edit another field I get the message :

"Another user edited this record and saved the changes before you attempted to save your changes.
Re-edit the record."

I can avoid this if I first hit the enter key, while the focus is still on the field Me!hdrBookmarkLink.
But I would like this to happen automatically, i.e. in the coding.

I tried with : DoCmd.GotoControl "OtherField" but this fails. It gives "Run-time error 2110 : cannot move the control ..."

I just need an Enter after the Past ...

TIA

95083-image.png

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
881 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DBG 2,301 Reputation points
    2021-05-10T04:27:39.627+00:00

    Hi. Just a guess, but try this:

    Private Sub Paste_Bookmark_Click()
    If Me.Dirty Then Me.Dirty=False
    Me!hdrBookmarkLink.SetFocus
    DoCmd.RunCommand acCmdPaste
    End Sub
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.