cancelling beforeUpdate on a Control

A

Andy Levy

Hi

I have a combobox called "Status" on my form. There are six string-type
values in the list.

I have a piece of code that should validate the change of status - in the
combo's beforeUpdate event. But it throws up an error when trying to change
the value back afterwards.

Here is the code ...........

Private Sub status_BeforeUpdate(Cancel As Integer)
'Living
If Me.status.OldValue = "Sold" And Not Me.status = "Sold" Then
Dim answer
answer = MsgBox("Changing the status from SOLD will remove Sold
Price and Weight data." & vbCrLf & vbCrLf & "Click OK to proceed",
vbOKCancel, "Change of Status")
If answer = 2 Then 'vbCancel
Cancel = True
Me.status = Me.status.OldValue
End If
End If
Exit Sub


The error i receive is
Runtime Error : code is given
The macro or function set to the beforeUpdate property for this field is
preventing myDatabase from saving the data in this field


Hope you can help

Thanks

Andy
 
P

PC Datasheet

Status does not have an OldValue until the new value is saved.

Substitute this line of code:
Me!Status.Undo

For:
Me.status = Me.status.OldValue
 
K

Ken Snell

You cannot set a control to a new value (or an old value) in the
BeforeUpdate event of that control...ACCESS will display an error message if
you try this.

Me.ControlName.Undo is the only way (and that only works for bound
controls).
 
P

PC Datasheet

Ken,

That's what I said! Reread my response.


Ken Snell said:
You cannot set a control to a new value (or an old value) in the
BeforeUpdate event of that control...ACCESS will display an error message if
you try this.

Me.ControlName.Undo is the only way (and that only works for bound
controls).
 

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