参考拆分表格?审核表未选择VBA

时间:2019-08-11 18:53:04

标签: vba ms-access

我正在尝试在MS Access中创建审核跟踪表单。审核表没有选择它。我对引用VBA条纹中的表格有疑问。谁能帮忙,如何引用拆分表格?如果以下脚本不正确。谢谢

Option Compare Database

Public Function AuditChanges(RecordID As String, UserAction As String)
On Error GoTo auditerr

Dim DB As DAO.Database
Dim rst As DAO.Recordset
Dim clt As Control
Dim UserLogin As String

Set DB = CurrentDb
Set rst = DB.OpenRecordset("select * from AuditTrail", dbOpenDynaset)

UserLogin = Environ("UserName")
Select Case UserAction
Case "new"
With rst
.AddNew
![DateTime] = Now()
!UserName = UserLogin
!FormName = Screen.ActiveForm.ActiveControl.Form.Name
!Action = UserAction
!RecordID = Screen.ActiveForm.ActiveControl.Form(RecordID).Value
.Update

End With


Case "Delete"
With rst
.AddNew
![DateTime] = Now()
!UserName = UserLogin
!FormName = Screen.ActiveForm.Name
!Action = UserAction
!RecordID = Screen.ActiveForm.Controls(RecordID).Value
.Update
End With

Case "Edit"
For Each clt In InScreen.ActiveForm.ActiveControl.Form
If (clt.ControlType = acTextBox _
Or clt.ControlType = acComboBox) Then
If Nz(clt.Value) <> Nz(clt.OldValue) Then
With rst
.AddNew
![DateTime] = Now()
!UserName = UserLogin
!FormName = Screen.ActiveForm.Name
!Action = UserAction
!RecordID = Screen.ActiveForm.Controls(RecordID).Value
!FieldName = clt.ControlSource
!OldValue = clt.OldValue
!newValue = clt.Value
.Update
End With
End If
End If
Next clt
End Select
rst.Close
DB.Close
Set rst = Nothing
Set DB = Nothing

auditerr:
'MsgBox Err.Number & " : " & Err.Description, vbCritical, "Error"
Exit Function



End Function

没有特定的错误,但是跟踪表没有被拾取/更新。

1 个答案:

答案 0 :(得分:0)

假设已将记录成功添加到AuditTrail表中,则应在修改基础表中保存的数据后调用表单的Requery方法。