Allowedits = true interfering with duplicate macro button

JOWINO

New member
Local time
Today, 14:21
Joined
Jul 12, 2024
Messages
5
Why does ms access form I recently added a button for me.allowedits = true and on current I set the vb code to me.allowedits = false interfering with my duplicate macro button returning a pop up message the command or action 'paste isn't available now. In ms access 2019
 
Sounds like your macro is adding the record via the form rather than via recordset or SQL? How about toggling the setting at the beginning/end of your macro?
 
maybe use VBA, to clearly see what you are doing:
Code:
' duplicate record
Private Sub cmdDuplicate_Click()
    Dim bolPrevState As Boolean
    If Me.NewRecord Then
        ' exit if on new record
        Exit Sub
    End If
    
    ' save prevous state of allowEdits
    bolPrevState = Me.AllowEdits
    ' set to allow edits
    Me.AllowEdits = True
    ' copy entire row
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    
    ' paste to new record
    DoCmd.RunCommand acCmdPasteAppend
    
    ' optional to
    ' save duplicated record
    DoCmd.RunCommand acCmdSaveRecord
    
    ' re-instate AllowEdits status
    Me.AllowEdits = bolPrevState
    
End Sub

' disable edits
Private Sub Form_Current()

    Me.AllowEdits = False
    
End Sub

' allow edits
Private Sub cmdAllowEdits_Click()

    Me.AllowEdits = True
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom