OldValue Property Not Working

L

Lorraine

When the value in textbox TypeID is updated I want there to be a Warning
through a message box. If the user clicks the "No" button I want there to be
an automatic "undo" of the change.

The message box displays and the Yes button functions, but when the No
button is selected I get a run-time error '2115' that states "The macro or
function set to the BeforeUpdate or ValidationRule property for this field is
preventing Microsoft Access from saving the data in the field." I don't have
a ValidationRule property set for this field.

Private Sub TypeID_BeforeUpdate(Cancel As Integer)
OriginalValue = TypeID.OldValue

RetValue = MsgBox("You are about to CHANGE or DELETE a TypeID. Are you sure
you want to do this?", 260 + vbCritical, "WARNING")

If RetValue = vbNo Then

For Each ctlTextbox In Me.Controls
If TypeID.ControlType = acTextBox Then
TypeID.Value = TypeID.OldValue
End If
Next ctlTextbox

End If
End Sub

In the nested If-Then statement, the TypeID.Value is capturing the updated
value and the TypeID.OldValue is capturing the value before update but this
is the line of code that is also being highlighted by the debugger.

Help me please.
 
M

Mr B

Lorraine,

I tried some of the BeforeUpdate event things, but did not have a lot of
success. I then tried the following:

Assuming that the "OriginalValue" is a variant type variable, then try:

Place the assignment of the current value to the variable to the On Enter
event of the control:
Private Sub TypeID_Enter(Cancel As Integer)
OriginalValue = TypeID.OldValue
end sub

The in the After Update event of the control:
Private Sub TypeID_AfterUpdate()
If Me.TypeID.Text <> OrignialValue Then
RetVal = MsgBox("Want to do this?", vbYesNo)
If RetVal = vbNo Then
'Cancel = True
'Me.TypeID.Undo
Me.TypeID = OrignialValue
End If
End If
End Sub

This worked for me.
 
L

Lorraine

Mr B,

I had to modify your code a bit by

#1 Omitting the "Cancel as Integer" argument in the TypeID_Enter Sub
Procedure.

#2 Needed to declare the variable "OriginalValue" as an Integer in the
module level so that the variable could be read between the TypeID_Enter and
the TypeID_AfterUpdate procedures.

It works beautifully now.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top