Creating a command button to edit a record

jscalfano

New member
Local time
Today, 14:54
Joined
Aug 12, 2011
Messages
2
I have a form that is set to allow edits no to prevent accidential changes to data. I am trying to write a command button the will allow a record to be changed and when saved set the allow edits back to no. I am very new at this and need help.
 
Hi. Try to use this codes! Hope it will help you...

Code:
Private Sub cmdsave_Click()
On Error Resume Next

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Me.AllowEdits = False

End Sub

Private Sub CmdEdit_Click()
On Error Resume Next

Me.AllowEdits = True
        

End Sub
 
DoMenuItem is an old command and should be avoided if possible. There's an equivalent action in DoCmd.RunCommand. Also, the OP wasn't asking for a save button ;)
Code:
Private Sub cmdsave_Click()
On Error Resume Next

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Me.AllowEdits = False

End Sub

I am trying to write a command button the will allow a record to be changed and when saved set the allow edits back to no.
The code should go in the form's After Update event.
Code:
Private Sub Form_AfterUpdate()
    Me.AllowEdits = False
End Sub
 
I prefer to toggle on / off the .enabled properties of each control on the form via a loop (excluding the ones which I don't want locked like search windows, command buttons, etc).

That way the fields are greyed out for a visual clue to the uneditable nature of the data and the data cannot be edited as the field isn't enabled.
 

Users who are viewing this thread

Back
Top Bottom