If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Creating a Cancel and Undo Button
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. |
#2
|
|||
|
|||
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) |
#3
|
|||
|
|||
How about using the Undo method of the form:
Private Sub Command39_Click() If Me.Dirty Then Me.Undo End If End Sub -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Nick in Tokyo" wrote in message ... 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. |
#4
|
|||
|
|||
How do you create a message box to check whether the user wants to cancel? I
do not know much about VB. Thanks "SJ McAbney" wrote: 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) |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Open form, Edit button, etc | Aniko | Using Forms | 14 | July 25th, 2004 08:17 AM |
Cancel Change In Option Group | Corrine | New Users | 1 | June 8th, 2004 12:07 PM |
Cancel Changes and exit Button | Richard Krupa | Using Forms | 1 | June 1st, 2004 12:20 AM |