OldValue property

shacket

Registered User.
Local time
Today, 19:30
Joined
Dec 19, 2000
Messages
218
I am getting a confusing message with this. I have a field that is a combobox on the form. I want to, under certain conditions, "undo" what the user has done (you will see what I mean in the code). When I run this, I get the following error message:

RunTime 2115: 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

Here is the code. Thanks for your help.

Code:
If Me.Combo52 = "Member" Then
    'Double check that they meant to make this person a member before
    'you record a membership date for them
    Response = MsgBox("You have changed " & Me.First & "'s membership type from " & Me.Combo52.OldValue & " to Member. Confirm " & _
        "this by clicking YES below." & Chr(13) & "If this is not your intention, click NO.", 0 + 4 + 256, "Changed to Member?")
    If Response = vbYes Then
        If Nz(Me.MembershipYear) = "" Then
            Me.MembershipYear = Date
        End If
    Else
        Me.Combo52.Value = Me.Combo52.OldValue    '<<<<This is the code causing the error
        Me.Refresh
        Exit Sub
    End If
End If

[This message has been edited by shacket (edited 09-19-2001).]
 
I assume this code is in the beforeupdate of the combo box (ie combo52_beforeupdate)

The problem (I beleive) is that your trying to change the value of combo52 while access is still running the code for it.

Try changing the procedure to afterupdate instead of beforeupdate and see if that works.
 
Try :

Else
Cancel = True
End If
 
Putting the code in the after update event wouldn't work because after it updates, the OldValue is the same as the control.

What I ended up having to do was record the OldValue in a variable and have another variable in the BeforeUpdate event tell whether the data is to be changed back. Then put the code (based on the second variable) to change the data back in the AfterUpdate event.

Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom