Undo action Not Available

pungentSapling

NeedHotSauce?
Local time
Today, 07:36
Joined
Apr 4, 2002
Messages
115
I have aan undo button on a form
problem is that if you click the undo button without making any changes to the record displayed on the form it is throwing an erorr about how the action is not available.

how can I get around this... people might click edit"calls editMode" then decide they didn't want to edit click cancel"undo" and then get confused by error message.
 
A couple of possibilities come to mind.

First, you could just turn off warnings in the code that is about to do the UNDO. Do the UNDO. Then turn on warnings again.

Second, you could (if you were being fancy) test whether any changes have occurred on the form and, if not, skip the UNDO step completely.

Either solution requires you to muck in the VBA code.

If you want to follow up on the second option, you would have to write a simple loop over all controls on the form to see if any of them that have property '.value' have values different from their property '.oldvalue' values.

Follow up in this same thread if you want to take the fancy approach but aren't sure about how to do so.
 
Private Sub Cancel_Click()
On Error GoTo Err_Cancel_Click


If Me.Dirty = True Then
Me.Undo
Else
MsgBox "There is nothing to Undo"
End If

Exit_Cancel_Click:
Exit Sub

Err_Cancel_Click:
MsgBox Err.Description
Resume Exit_Cancel_Click

End Sub
 
I use something similar as Rich...

Private Sub bUndo_Click()
On Error GoTo Err_bUndo_Click

If Me.Dirty Then
Beep
DoCmd.RunCommand acCmdUndo
Else
Beep
MsgBox "There were no modifications made to the current record.", vbInformation, "Invalid Undo"
End If

Exit_bUndo_Click:
Exit Sub

Err_bUndo_Click:
MsgBox Err.Number, Err.Description
Resume Exit_bUndo_Click

End Sub

HTH
 

Users who are viewing this thread

Back
Top Bottom