From: ll on
Hi,
I have added an Undo Changes button to my Access form, and I would
like to somehow disable it after each click and re-enable it when a
change is made to the form. Currently, I have the following code.
Thanks for any help you might be able to give.

Regards,
Louis

==============================
Private Sub Form_Current()
Me!cmdUndoChanges.Enabled = False
End Sub

Private Sub Form_Dirty(Cancel As Integer)
Me!cmdUndoChanges.Enabled = True
End Sub

Private Sub cmdUndoChanges_Click()
On Error GoTo Err_undoChanges_Click
DoCmd.RunCommand acCmdUndo

Exit_undoChanges_Click:
Exit Sub

Err_undoChanges_Click:
MsgBox Err.Description
Resume Exit_undoChanges_Click

End Sub

From: missinglinq via AccessMonster.com on
You need to add these two lines as in the code below

Me!AnyControlName.SetFocus 'Set focus to any control other than
cmdUndoChanges
Me!cmdUndoChanges.Enabled = False 'Disable the button

The first line is necessary because you can't disable a control if it had
focus. Replace

AnyControlName

with the actual name of another control on your form.

Code
==============================
Private Sub cmdUndoChanges_Click()
On Error GoTo Err_undoChanges_Click

DoCmd.RunCommand acCmdUndo

Me!AnyControlName.SetFocus
Me!cmdUndoChanges.Enabled = False

Exit_undoChanges_Click:
Exit Sub

Err_undoChanges_Click:
MsgBox Err.Description
Resume Exit_undoChanges_Click

End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200704/1