我最近开发了一个MS Access 2010数据库,我想添加跟踪每个用户活动的功能。在我看来,我可以创建一个Activity
表,然后向每个表单添加代码,只要用户在数据库中创建,查看,编辑或删除记录,就会向Activity表添加一行。但是我该如何做到以下几点:
1.) Identify a specific user: Is there a User object so that calling something
like User.getName() returns "JaneDoe" or "SallySmith" and I can thus store
history for that specific user in the Activity table? What is the syntax
for retrieving the current user's username?
2.) Lock down tables permanently so that only specified forms can create, modify,
or delete records in specific tables.
3.) Make sure that the Activity table cannot be edited by anyone other than one
specific administrator account.
为了让您更好地理解我对上述三个问题的意义,Activity表的结构可能包括以下字段:
id (primary key)
userName (the name of the user who made the operation)
tableName (the name of the table that was changed)
operation (the type of change, such as create, edit, delete)
rowNumber (the autonumber primary key of the changed field)
date (the date the change was made)
我可能会添加更广泛的日志记录,但是在这个级别进行设置将使我们能够在变得更复杂之前确保一切正常。
有人可以解释我上述三个问题的答案吗?链接到答案中的更多信息将非常有帮助。
MS Access 2010中是否已经内置了这样的内容?或者我必须自己滚动?
答案 0 :(得分:2)
对于用户名问题,您可以使用Windows API函数GetUserNameW:
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameW" (ByVal lpBuffer As Long, ByRef lpnSize As Long) As Long
Public Function GetWindowsUserName() As String
Dim Bytes(0 To 511) As Byte
Dim size As Long
size = 256
If GetUserName(VarPtr(Bytes(0)), size) = 0 Then
'There was an Error calling the API function
End If
If size > 0 Then
GetWindowsUserName = Mid(Bytes, 1, size)
End If
End Function
如果你想要低级日志记录,我建议最好的方法是为Recordset类创建一个包含所有相同方法的包装器,但在调用底层Recordset成员之前,执行任何日志记录你要。不幸的是,我测试过并且无法使用`Implements DAO.Recordset"。我收到了错误"编译错误:实现的接口错误:接口是从另一个纯接口派生的,带有非限制方法" - 给我一个新的:P