Subform Undo button in masterform

J

JOM

I have a subform that is in a datasheet view, I also have an undo button in
the master form. I would like that if I make any changes in the subform,
that I would be able to undo the changes using the undo button thats on the
master form. When I make changes, and press undo, popup box says that undo is
not available now Currently i have the following code in the subform

Private Sub Form_Current()
Forms![Emplmasterform].[Form]!cmdUndo.Enabled = False

End Sub

Private Sub Form_Dirty(Cancel As Integer)
Forms![Emplmasterform].[Form]!cmdUndo.Enabled = True

End Sub

**************************************************
'undo code, button in the masterform!
*************************************************
Sub cmdUndo_Click()
On Error GoTo Err_cmdUndo_Click

DoCmd.RunCommand acCmdUndo

Exit_cmdUndo_Click:
Exit Sub

Err_cmdUndo_Click:
MsgBox Err.Description
Resume Exit_cmdUndo_Click

End Sub
 
O

Ofer

As much that I knew you can't undo the changs you made in your record, the
second you get out of row the record is saved in the table, you can undo the
changes you make only on the before update of the record.

if you want to have the ability to undo your changes , when you load th form
save the data on a temp table, if the user press the undo button then delete
the records from the main table and append the records back from the temp
table, and then refresh the sub form.
 
V

Van T. Dinh

Your idea won't work in Form / Subform combination.

When you click the cmdUndo button, the Focus goes out out the Subform and
the Record on the Subform must be saved / updated before the Subform loses
the Focus. Thus by the time the code in your cmdUndo button is executed,
the Record in the Subform has been saved / updated and Undo won't work.

BTW, even if the above were not a problem, the code you posted is incorrect.
Your code will undo the Main Form, not the Subform since the Focus is on the
CommandButton cmdUndo, i.e. the active Data Object is the Main Form and this
is where the Undo action will be applied.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top