I have code that I use to track the changes on one of my forms….Now when I make changes, I receive an error:
“The expression you entered has a field, control, or property name that Microsoft Access can’t find.”
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim db As DAO.Database
Dim ctl As Control
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset(“tblChanges”)
On Error GoTo Form_BeforeUpdate_Error
For Each ctl In Me.Controls
If TypeOf ctl Is Label Then
‘Do nothing
Else
If Nz(ctl.OldValue) Nz(ctl.Value) Then
With rst
rst.AddNew
rst!Fields(“Rank”) = RANK
rst!Fields(“LNAME”) = LNAME
rst!Fields(“FNAME”) = FNAME
rst!Fields(“MI”) = MI
rst!Fields(“SSN”) = SSN
rst!Fields(“MOS”) = MOS
rst!Fields(“COMPANY”) = COMPANY
rst!Fields(“OBJECT_CHANGED”) = Me.Name
rst!Fields(“PRIOR_VALUE”) = ctl.OldValue
rst!Fields(“CURRENT_VALUE”) = ctl.Value
rst!Fields(“CHANGED_BY”) = GetNetUser()
rst.Update
End With
End If
Next ctl ‘Compile Error: Next without For
On Error GoTo 0
rst.Close
End If
Exit Sub
Form_BeforeUpdate_Error:
If Err.Number = 2427 Then ‘this is the error number for something which does not have any data, and therefore does not have an “oldvalue”.
Resume Next
Else
MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in procedure Form_BeforeUpdate”
End If
End Sub
I’m hoping this is fixable in methods other than redesigning/importing to a new database.