I get "runtime error 2448, You can't assign a value to this object" when I try to update a field in an existing record. This same sub successfully assigns the value when the record is new, and I'm ripping out my hair to figure out why.
The purpose of this code is to record the previous value into an audit trail table to record changes to the record. The click event records the value of the field in a variable "oldInitAct", and then here in the AfterUpdate the new value is compared to the old to see if it changed. If it has changed it writes the value to the audit table in the addComment () function, and then tries to make the change. If oldInitAct is Null, then the audit route is skipped and the value is successfully updated. If the value has changed then it fails to update the field with the new value using similar code, [INITIAL_ACTIVITY] = InitialActivity.Value
I have tried:
1. Using me.INITIAL_ACTIVITY = InitialActivity.Value
2. Using me!INITIAL_ACTIVITY = InitialActivity.Value
3. Moving the three variations of the statement before the IF THEN comparison, just to see if it would work
4. Moving it to a different function.
I get 2448 every time. Why does this happen?
Edit: the field is defined as "Numeric", and running MsgBox (IsNumeric(InitialActivity.Value)) returns "True"Code:Private Sub initialActivity_AfterUpdate() Dim localInitAct As Variant localInitAct = InitialActivity.Value If IsNull(oldInitAct) Then GoTo skipCheck Else If localInitAct <> oldInitAct Then If MsgBox("Initial Activity already has a value of " & oldInitAct & " Would you like to update it? ", vbYesNo + vbQuestion) = vbYes Then [INITIAL_ACTIVITY] = InitialActivity.Value commentString = ("Initial Activity was changed from " & oldInitAct) addComment (commentString) GoTo endMe Else GoTo skipCheck End If End If End If skipCheck: MsgBox (InitialActivity.Value) [INITIAL_ACTIVITY] = InitialActivity.Value MsgBox ("DONE") endMe: End Sub