A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Creating a Cancel and Undo Button



 
 
Thread Tools Display Modes
  #1  
Old August 19th, 2004, 08:37 AM
Nick in Tokyo
external usenet poster
 
Posts: n/a
Default 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  
Old August 19th, 2004, 09:59 AM
SJ McAbney
external usenet poster
 
Posts: n/a
Default


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  
Old August 19th, 2004, 09:59 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default

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  
Old August 19th, 2004, 11:55 AM
Andrew Wilkins
external usenet poster
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 12:25 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.