cancelling beforeUpdate on a Control

  • Thread starter Thread starter Andy Levy
  • Start date Start date
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
 
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
 
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).
 
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).
 
Back
Top