Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo/Cancel

Status
Not open for further replies.

richardii

Programmer
Jan 8, 2001
104
0
0
GB
I'm having no luck writing a Cancel button for a subform. The cancel will undo changes for the main form, but won't do anything for the subform. Setting the focus to the subform and then .undo results in the BeforedelConfirm event being called!! So I thought I'd try this (from the Help). But ctl causes a problem. When I change it to ctlTextBox the .OldValue is the same as the .Value! The help talks about writing your own Undo, but how?!

Sub btnUndo_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
 
You'll need to add the undo on the subform. The subform will need to be set as a continuous form(not datasheet). Add the button to either the subform's header or you could add it to the detail section of the form(if you do this it will be displayed on the same row as the records). Make sure the undo includes the entire path, don't use the Me. keyword.

Forms!MainFormName.SubFormName.Undo
 
JerryDennison -
I am trying to perform similar actions as richardii. I had created a public function in my subform that works well. As you mentioned, once it is moved to the main form, the code does not work.

In my research and reading, I have not found any mention that a subform's actions cannot be referenced from a main form.

Could you expand upon your explanation a little. I am interested to learn more about this. Unfortunately, this problem comes late in my project and I am unsure on how to resolve it. That is why your input is so valuable...

Thank you,
Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top