Avatar of Rob4077
Rob4077
Flag for Australia asked on

3251 Operation is not supported for this type of object

I have tried to create a function that provides a basic audit trail of changes using the following code. For certain controls (textboxes and comboboxes) I am getting error 3251 Operation is not supported for this type of object. There is no trouble with the Value but it is oldValue that is fouling up and I don't know why. What are the restrictions on accessing the oldValue of a field?


Public Function LogChanges(frm As Form)
    'This function creates a text file in the Logs sub-folder for every day and records changes made to field values in monitored forms
    Dim hFile As Integer
    Dim sLogFileName As String
    Dim ctl As Control
    Dim sKeyIdentifier As String
           
    sKeyIdentifier = " Did: " & Nz(frm.DetailId)
   
    On Error GoTo cLog_Error

    sLogFileName = Format(Now, "yymmdd") & "_" & Environ$("computername") _
        & "_" & Environ$("username") & "_" _
        & Left([CurrentProject].[Name], InStrRev([CurrentProject].[Name], ".") - 1) & ".txt"

    On Error Resume Next ' CREATE THE REQUIRED SUB-FOLDER IF NOT ALREADY CREATED
    MkDir SERVERPATH & "\ChangeLogs\"
    On Error GoTo cLog_Error
   
    hFile = FreeFile
   
    Open SERVERPATH & "\ChangeLogs\" & sLogFileName For Append As #hFile
   
    Print #hFile, Format(Now(), "hh:nn:ss") & ": " & frm.Name & sKeyIdentifier
   
    On Error GoTo cLogLoopError
    For Each ctl In frm   '.Controls
        If ctl.ControlType <> acLabel Then
        If Len(ctl.ControlSource) > 0 Then  'This variable is linked to a table so change should be logged
            If Nz(ctl.Value, "") <> Nz(ctl.OldValue, "") Then
                Print #hFile, String(4, " ") _
                    & Left(ctl.Name, 30) & Space(30 - Len(Left(ctl.Name, 30))) _
                    & "|" & Left(ctl.ControlType, 4) & Space(4 - Len(Left(ctl.ControlType, 4))) _
                    & " |> " & Nz(ctl.OldValue, "")
               
                Print #hFile, String(4, " ") _
                    & Left(ctl.Name, 30) & Space(30 - Len(Left(ctl.Name, 30))) _
                    & "|" & Left(ctl.ControlType, 4) & Space(4 - Len(Left(ctl.ControlType, 4))) _
                    & " >> " & Nz(ctl.Value, "")
            End If
        End If
        End If
NextControl:
    Next ctl
    Set ctl = Nothing

ExitFunction:
    Close #hFile

    On Error GoTo 0
    Exit Function

cLogLoopError:
    If Err.Number = 438 Then Resume NextControl 'Object doesn't support this property or method
   
    Debug.Print ctl.Name & " error: " & Err.Number & " " & Err.Description & " Type: " & ctl.ControlType
    'Stop
    Resume NextControl
    Resume

cLog_Error:
Stop
    If Err.Number = 70 Then Resume ExitFunction
    GoTo ExitFunction

End Function
Microsoft Access

Avatar of undefined
Last Comment
Rob4077

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
bfuchs

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rob4077

ASKER
Modified it to work for me. Thanks
SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Jim Dettman (EE MVE)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rob4077

ASKER
Thanks everyone for your comments. I will award the bulk of the points to bfuchs but thank you both Jim and Dale for your additional comments. I will modify my auditing as you suggest.
Your help has saved me hundreds of hours of internet surfing.
fblack61