如何解决错误 483:“对象不支持此属性或方法”

时间:2021-05-28 16:20:51

标签: vba ms-access

我为我的 MS-Access 数据库创建了一个审计跟踪 vba 代码:我复制了代码,并让它在“新”案例中工作:

但是当我尝试执行“更新”时出现错误 483:

代码如下:

Option Compare Database

Public Function AuditLog(RecordID As String, UserAction As String)
On Error GoTo AuditErr

Dim DB As Database
Dim rst As Recordset
Dim ctl As Control
Dim UserLogin As String

Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT * from tbl_AuditLog")

UserLogin = Environ("Username")

Select Case UserAction
    Case "New"
        With rst
            .AddNew
            ![EditDate] = Now()
            ![User] = UserLogin
            !FormName = Screen.ActiveForm.Name
            !Action = UserAction
            !RecordID = Screen.ActiveForm.Controls(RecordID)
            .Update
        End With
        
    Case "Delete"
        With rst
            .AddNew
            ![EditDate] = Now()
            ![User] = UserLogin
            !FormName = Screen.ActiveForm.Name
            !Action = UserAction
            !RecordID = Screen.ActiveForm.Controls(RecordID)
            .Update
        End With
        
    Case "Edit"
        For Each ctl In Screen.ActiveForm.Controls
            If (ctl.controltpe = acTextBox _
                Or ctl.ControlType = acComboBox) Then
                If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
                    With rst
                      .AddNew
                        ![EditDate] = Now()
                        ![User] = UserLogin
                        !FormName = Screen.ActiveForm.Name
                        !Action = UserAction
                        !RecordID = Screen.ActiveForm.Controls(RecordID)
                        !FieldName = ctl.ControlSource
                        !OldValue = ctl.OldValue
                        !NewValue = ctl.Value
                        .Update
                    End With
                End If
            End If
        Next ctl
End Select
rst.Close
DB.Close
Set rst = Nothing
Set DB = Nothing

AuditErr:
    If Err.Number = 0 Then
        Exit Function
    Else
        MsgBox Err.Number & " :: Unable to create audit log ::" & Err.Description
    End If
    Exit Function
    
End Function

它特别在这一行中断:

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

现在我再次复制了这段代码,并在它工作的代码的源代码中。但我觉得,这里一定缺少一些东西。我只是不知道是什么。任何人都能够看到错误,或者为我指明一个好的开始方向?

0 个答案:

没有答案