Results 1 to 15 of 15
  1. #1
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231

    Object Not Supported

    I'm using Martin Green's audit table code to track changes to my database. From the main business member form, the user can select to create a new member and then I call up the edit form to allow the user to enter in data. But I prefill the edit form with the new company name, so I think the code, which is looking for the action to be either "NEW" or "EDIT", deems this to be a new record. Which is correct.



    But I've altered Martin's code for the section under CASE ELSE because for some reason when it gets to this point, the action is still be recorded as EDIT and I've tried to replicate the code to be what's above.

    So I don't understand why the line "If Nz(ctl.Value) <> Nz(ctl.OldValue) Then" works in the upper section, but won't allow me to use it in the CASE ELSE section.
    Plus, if I comment out this line, the line further below ![OldValue] = ctl.OldValue causes an error.

    Plus, after implementing this code, there is never an entry for "NEW" rather they're all "EDIT".

    Confused....CementCarver








    Sub AuditChanges(MEMBER_ID As String, UserAction As String)
    'On Error GoTo AuditChanges_Err
    Dim cnn As ADODB.Connection
    Dim rstAudit As Recordset
    Dim ctl As Control
    Dim datTimeCheck As Date
    Dim strUserID As String
    Dim MaxMember_id As Integer
    Dim db As Database

    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    rst.Open "Select * from Audit_Trail", cnn, adOpenDynamic, adLockOptimistic
    datTimeCheck = Now()
    strUserID = CurrentUser()

    MaxMember_id = DMax("[MEMBER_ID]", "BUSINESS")

    Select Case UserAction
    Case Edit
    For Each ctl In Screen.ActiveForm.Controls
    If ctl.Tag = Audit Then
    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then
    If Nz(ctl.Value) <> Nz(ctl.OldValue) Then..............BUT THIS IS THE SAME LINE BELOW AND THIS ONE WORKS...!!!
    With rst
    .AddNew
    ![DateTime] = datTimeCheck
    ![UserName] = strUserID
    ![FormName] = Screen.ActiveForm.Name
    ![Action] = UserAction
    ![Record_ID] = MaxMember_id
    ![FieldName] = ctl.ControlSource
    ![OldValue] = ctl.OldValue
    ![NewValue] = ctl.Value
    .Update
    'Debug.Print "Current values " & UserAction
    End With
    End If
    End If
    End If
    Next ctl
    Case Else
    For Each ctl In Screen.ActiveForm.Controls
    If ctl.Tag = Audit Then
    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then
    If (ctl.Value) <> (ctl.OldValue) Then .............THIS IS THE LINE WHERE IT STOP AND GIVES ME AN ERROR AND IF I COMMENT THIS LINE, THEN THE LINE BELOW WHICH TRIES TO LOAD THE !OLDVALUE CAUSES AN ERROR......
    With rst
    .AddNew
    ![DateTime] = datTimeCheck
    ![UserName] = strUserID
    ![FormName] = Screen.ActiveForm.Name
    ![Action] = UserAction
    ![Record_ID] = MaxMember_id
    ![FieldName] = ctl.ControlSource
    ![OldValue] = ctl.OldValue........CAUSES AN ERROR IF THE IF STATEMENT ABOVE IS COMMENTED OUT...
    ![NewValue] = ctl.Value
    .Update
    End With
    End If
    End If
    End If
    Next ctl
    End Select
    AuditChanges_exit:
    On Error Resume Next
    rst.Close
    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing
    Exit Sub
    AuditChanges_Err:
    MsgBox Err.Description, vbCritical, "Error!"
    Resume AuditChanges_exit
    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I found a few errors that need to be fixed.

    ---------------------------------------------
    You declare a recordset using

    Dim rstAudit As Recordset

    But then you refer to a recordset "rst":

    Set rst = New ADODB.Recordset
    rst.Open "Select * from Audit_Trail", cnn, adOpenDynamic, adLockOptimistic


    ------------------------------------------------------
    In the "Select Case ...End Select" construct, "UserAction" is text (a string), so the "Case" options have to have quotes
    Code:
       Select Case UserAction
          Case "Edit"
    
          Case Else
       End Select

    ------------------------------------------------
    In this line, Audit needs quotes. (in 2 lines)
    Code:
                If ctl.Tag = "Audit" Then

    ------------------------------------------------------------
    In the lines that causes an error, the lines are different:
    Code:
    Case "Edit"
           If Nz(ctl.Value) <> Nz(ctl.OldValue) Then     '..............BUT THIS IS THE SAME LINE BELOW AND THIS ONE WORKS...!!!
    
    Case Else
           If (ctl.Value) <> (ctl.OldValue) Then   '.............THIS IS THE


    -----------------------------------------------------
    Also, do you have these two lines at the top of every module?

    Option Compare Database
    Option Explicit ' <<- this helps to find undeclared variables.

  3. #3
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Thanks Steve,

    I was just playing with the code and trying different things to make it work. I'll make the appropriate changes and see what happens.

    CementCarver

  4. #4
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Sub AuditChanges(MEMBER_ID As String, UserAction As String)
    'On Error GoTo AuditChanges_Err
    Dim cnn As ADODB.Connection
    Dim rstAudit As ADODB.Recordset
    Dim ctl As Control
    Dim datTimeCheck As Date
    Dim strUserID As String
    Dim MaxMember_id As Integer

    Set cnn = CurrentProject.Connection
    Set rstAudit = New ADODB.Recordset
    rstAudit.Open "Select * from Audit_Trail", cnn, adOpenDynamic, adLockOptimistic
    datTimeCheck = Now()
    strUserID = CurrentUser()

    MaxMember_id = DMax("[MEMBER_ID]", "BUSINESS")

    Select Case UserAction
    Case "Edit"
    For Each ctl In Screen.ActiveForm.Controls
    If ctl.Tag = "Audit" Then
    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then
    If Nz(ctl.Value) <> Nz(ctl.OldValue) Then.... List line still causes an error..... Object Not supported.
    With rstAudit
    .AddNew
    ![DateTime] = datTimeCheck
    ![UserName] = strUserID
    ![FormName] = Screen.ActiveForm.Name
    ![Action] = UserAction
    ![Record_ID] = MaxMember_id
    ![FieldName] = ctl.ControlSource
    ![OldValue] = "No Value"... And if I comment out the error line above, this line still causes the same problem, Object not supported.
    ![NewValue] = ctl.Value
    .Update
    'Debug.Print "Current values " & UserAction
    End With
    End If
    End If
    End If
    Next ctl
    Case "Else"
    For Each ctl In Screen.ActiveForm.Controls
    If ctl.Tag = "Audit" Then
    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then
    If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
    With rstAudit
    .AddNew
    ![DateTime] = datTimeCheck
    ![UserName] = strUserID
    ![FormName] = Screen.ActiveForm.Name
    ![Action] = UserAction
    ![Record_ID] = MaxMember_id
    ![FieldName] = ctl.ControlSource
    ![OldValue] = ctl.OldValue
    ![NewValue] = ctl.Value
    .Update
    End With
    End If
    End If
    End If
    Next ctl
    End Select
    AuditChanges_exit:
    On Error Resume Next
    rstAudit.Close
    cnn.Close
    Set rstAudit = Nothing
    Set cnn = Nothing
    Exit Sub
    AuditChanges_Err:
    MsgBox Err.Description, vbCritical, "Error!"
    Resume AuditChanges_exit
    End Sub

  5. #5
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Because I have another line in the code that doesn't exist in Martin Green's example ie.

    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then

    Are there any control types that do not support comparison of newvalue to oldvalue?

    CementCarver

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The line "Case Else" is part of the Select Case Statement. The ELSE should NOT have quotes around it.

    You are passing the member ID as an argument of the Sub, but you don't use it anywhere.
    Then you get the max member ID using :
    Code:
    MaxMember_id = DMax("[MEMBER_ID]", "BUSINESS")
    The MaxMember_id is not connected to the string "MEMBER_ID" because there is no criteria in the DMAX function. It will ALWAYS return the max member ID - no matter what!



    Adding this line:
    Code:
    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then
    does not add anything of value. The code searches every control on the form to see if the TAG property has a value of "Audit". If a control's TAG property does not have "Audit", it is skipped. So the line is unnecessary.

    When UserAction = "Edit", the code for Case "Edit" executes. For all other cases (where UserAction is NEW or DELETE or BANANA or BYE, or ...) the else code executes.


    I created the audit table and ran the code. Well, I ran the code I modified.
    I had to comment out 3 or 4 of your customizations. Otherwise, it ran great.
    Here is my revised code:
    Code:
    Sub AuditChanges(MEMBER_ID As String, UserAction As String)
       'On Error GoTo AuditChanges_Err
       Dim cnn As ADODB.Connection
       Dim rstAudit As ADODB.Recordset
       Dim ctl As Control
       Dim datTimeCheck As Date
       Dim strUserID As String
       Dim MaxMember_id As Integer
    
       Set cnn = CurrentProject.Connection
       Set rstAudit = New ADODB.Recordset
       rstAudit.Open "Select * from tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
       datTimeCheck = Now()
       strUserID = CurrentUser()
    
       MaxMember_id = DMax("[MEMBER_ID]", "BUSINESS")
    
       Select Case UserAction
          'existing records
          Case "Edit"
             For Each ctl In Screen.ActiveForm.Controls
                If ctl.Tag = "Audit" Then
                   If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
                      With rstAudit
                         .AddNew
                         ![DateTime] = datTimeCheck
                         ![UserName] = strUserID
                         ![FormName] = Screen.ActiveForm.Name
                         ![Action] = UserAction
                         ![Record_ID] = MaxMember_id
                         ![FieldName] = ctl.ControlSource
                         ![OldValue] = ctl.OldValue
                         ![NewValue] = ctl.Value
                         .Update
                         'Debug.Print "Current values " & UserAction
                      End With
                   End If
                End If
             Next ctl
          Case Else
             ' New or deleted records
             For Each ctl In Screen.ActiveForm.Controls
                If ctl.Tag = "Audit" Then
             '      If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
                      With rstAudit
                         .AddNew
                         ![DateTime] = datTimeCheck
                         ![UserName] = strUserID
                         ![FormName] = Screen.ActiveForm.Name
                         ![Action] = UserAction
                         ![Record_ID] = MaxMember_id
                         ![FieldName] = ctl.ControlSource
                         '     ![OldValue] = ctl.OldValue
                         ![NewValue] = ctl.Value
                         .Update
                      End With
             '      End If
                End If
             Next ctl
       End Select
    AuditChanges_exit:
       On Error Resume Next
       rstAudit.Close
       cnn.Close
       Set rstAudit = Nothing
       Set cnn = Nothing
       Exit Sub
    AuditChanges_Err:
       MsgBox Err.Description, vbCritical, "Error!"
       Resume AuditChanges_exit
    End Sub
    It helps if you comment the code.....

  7. #7
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Thanks Steve for your review and return comments. I'll try your code sample too.

    I appreciate you commenting back.

    CementCarver

  8. #8
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Steve... pasted in your code, exactly as it stands and I still get the same error for this line :

    If Nz(ctl.Value) <> Nz(ctl.OldValue) Then

    And if I comment out the line, as again before, the line:

    ![OldValue] = ctl.OldValue produces the same error.

    CementCarver

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would have to see your dB...the code should not error out. Would you post the dB with a couple of records?

    In the meantime, try adding the line in blue:
    Code:
          Case "Edit"
             For Each ctl In Screen.ActiveForm.Controls
                If ctl.Tag = "Audit" Then
                MsgBox "Control Name = " & ctl.Name & vbNewLine & "Control Type = " & ctl.ControlType & vbNewLine & "Old = " & ctl.OldValue & vbNewLine & "New = " & ctl.Value
                   If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
                      With rstAudit
                         .AddNew
                         ![DateTime] = datTimeCheck
                         ![UserName] = strUserID
                         ![FormName] = Screen.ActiveForm.Name
                         ![Action] = UserAction
                         ![Record_ID] = MaxMember_id
                         ![FieldName] = ctl.ControlSource
                         ![OldValue] = ctl.OldValue
                         ![NewValue] = ctl.Value
                         .Update
                         'Debug.Print "Current values " & UserAction
                      End With
                   End If
                End If
             Next ctl
    Write down each control type, then you will know which control type might be causing the error.

    Control Type (Number)
    ------------------------

    • Label 100
    • Rectangle 101
    • Line 102
    • Command Button 104
    • Option Button 105
    • Check Box 106
    • Frame 107
    • Text Box 109
    • List Box 110
    • Combo Box 111
    • Toggle 122
    • Tab control 123
    • Tabbed Page 124

  10. #10
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Thanks again Steve. I'll add the new line you've provided and see where that leads me. I am using a company's data and have signed a confidentially agreement, but if this line does lead me to solve this problem, I may just have to fictitiously created a sample of my db.

    Thanks again...CementCarver

  11. #11
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Gosh, darn it.... same error...Run-time error 3251....Object is not supported for this type of object. After adding your line:

    MsgBox "Control Name = " & ctl.Name & vbNewLine & "Control Type = " & ctl.ControlType & vbNewLine & "Old = " & ctl.OldValue & vbNewLine & "New = " & ctl.Value

    I even tried the debug.print in front and it even didn't like that.......

    What in tarn nations is this thing....?

    CementCarver

  12. #12
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Odd thing... it doesn't like the ctl.value portion and once I remove this, I do get a listing of the controls and their types. It stops at one control and if I'm suspecting correctly, the next box, which is a text box meant to input comments in, may be the culprit. But, as usual, it seems fine, with the tag="Audit" correctly set. But can't see anything wrong with it.

    CementCarver

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I may just have to fictitiously created a sample of my db.
    That works for me.

    I just want to see the actual dB and look at the actual forms/code.

  14. #14
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Steve,

    Can I send it to you privately?

    CC

  15. #15
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yep, sent you a PM

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Operation is not supported for this type of object error
    By CementCarver in forum Programming
    Replies: 4
    Last Post: 06-17-2013, 02:04 PM
  2. JOIN expression not supported
    By seageath in forum Access
    Replies: 2
    Last Post: 12-05-2011, 08:41 PM
  3. Object not supported "ERROR"
    By Casper2012 in forum Forms
    Replies: 1
    Last Post: 08-24-2011, 06:31 PM
  4. Join Expression not Supported
    By amegahed3 in forum Queries
    Replies: 6
    Last Post: 09-29-2010, 01:28 PM
  5. Join Expression Not Supported
    By ubsman in forum Queries
    Replies: 3
    Last Post: 04-30-2009, 08:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums