Creating a Cancel and Undo Button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm rubbish at VB so need a little help setting this up please. I want to
create a Cancel button that will return all the values in the form to the old
value. I found the oldvalue property and put this into the OnClick

Private Sub Command39_Click()
Dim ctlTextbox As Control
For Each ctlTextbox In Me.Controls
If ctlTextbox.ControlType = acTextBox Then
ctlTextbox.Value = ctl.OldValue
End If
Next ctlTextbox
End Sub

Do I have to set the oldValue for each control On Open? If someone could
help me out with the code for this I would really be grateful.
 
I found the oldvalue property and put this into the OnClick

Private Sub Command39_Click()
Dim ctlTextbox As Control
For Each ctlTextbox In Me.Controls
If ctlTextbox.ControlType = acTextBox Then
ctlTextbox.Value = ctl.OldValue
End If
Next ctlTextbox
End Sub

Do I have to set the oldValue for each control On Open?

The code you need is actually a lot simpler than this.

Private Sub Command39_Click()
Me.Undo
End Sub

I'd recommend putting a message box within the subroutine
to ensure that the user actually wants to Undo and hasn't
pressed the button by accident. Also, consider changing
the name of your button to something more meaningful
(i.e. cmdUndo)
 
How about using the Undo method of the form:

Private Sub Command39_Click()
If Me.Dirty Then
Me.Undo
End If
End Sub
 
How do you create a message box to check whether the user wants to cancel? I
do not know much about VB.

Thanks
 
Back
Top