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!

OldValue and Undo?

Status
Not open for further replies.

poctok

Technical User
Jun 1, 2001
15
0
0
GB
Hi,

I'm trying to use the Undo example in Microsoft Help (see below) on a form to reset the values of txt controls but keep getting the following error:

Run-time error '424'
Object Required

Can anybody help me?

Poctok

***
Example from Help -

Private Sub cmdUndoEdits_Click()

Private 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
 
Try this:

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

--------------
A little knowledge is a dangerous thing.
 
Thanks for your post, but still no joy. When I use the ammended code I get the following error:

Run-time error '2448'
You can't assign a value to this object

This was the error I was getting when I used the other example in help.

Completely lost!
 
...sorry, replace the .value with .text --------------
A little knowledge is a dangerous thing.
 
Thanks again - what you said makes sense and I thought it should work but no... this time the error is:

Run-time error 2185
You can't reference a property or method for a control unless the control has the focus.

I thought the point of the code was to loop through each of the controls?
 
hi

i tried the procedure and it worked fine...

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

it should works only with bound control --> meaning linked to a table.
 
I think I know why it doesn't work. I have an autonumber field in my table. Testing this on a simple form with no autonumbers it works.

Is there a way to exclude the autonumber control from the code? And get it to just update the text controls?

Thanks for the help so far.
 
Only assign the OldValue if the textbox isn't your autonumber textbox. Check it's name to see:

if ctlTextBox.Name <> &quot;InsertNameHere&quot; then
'Do your processing here...
end if --------------
A little knowledge is a dangerous thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top