我正在设计一个Access数据库,我想建立一个用户历史跟踪系统。
我的目标:保存所有登录和用户操作(登录尝试和搜索)
这样做,我有1张桌子和2张表格:
首先关注登录系统:
我怎样才能将操作注册为"登录成功"在评论中每次登录成功并尝试登录相反的情况?
例如有 24/03/15 - User1 - 登录对话 - - 登录成功 24/03/15 - User2 - 登录对话 - - 尝试登录 24/03/15 - 用户1 - 导航表格 - - 注销
以下是我首先编码的内容:
Const cDQ As String = """"
Public Function Loginwrong()
'Set the sql equality
Dim strsql As String
strsql = "INSERT INTO" & "[User activity tracker](Date, User, Soucetable, Researchhistory, Comments)" & _
"VALUES (Now()," & cDQ & frm.RecordSource.login & cDQ & "," & frm.RecordSource & cDQ & ", Attempt login)"
DoCmd.RunSQL strsql
End Function
面对它,我尝试了另一种方法:
Public Function Loginyes()
'Set the sql equality
Dim strsql As String
strsql = "INSERT INTO " _
& "[User Activity Tracker] (Date, User, SourceTable, " _
& " ResearchHistory, Comments) " _
& "VALUES (Now()," _
& cDQ & Environ("login") & cDQ & ", " _
& cDQ & frm.RecordSource & cDQ & ", " _
& cDQ & "," _
& cDQ & "Login success" & cDQ & ")"
'View evaluated statement in Immediate window.
Debug.Print strsql
DoCmd.SetWarnings False
DoCmd.RunSQL strsql
DoCmd.SetWarnings True
DoCmd.RunSQL strsql
你有什么见解吗?评论?想法?
答案 0 :(得分:0)
*我终于找到了这个功能的解决方案。
只是粘贴它以防其他人需要它:
Public Function Loginwrong()
'Define the elements dimensions
Dim frm As Form
Dim strsql As String
'Set the equality to have the current form used taken into account
Set frm = Screen.ActiveForm
'Use it to find values of the given controls
strsql = "INSERT INTO [User Activity]([Date], [User], SourceTable, Comments)" _
& "" & "VALUES(Now()," & "'" & frm.[login].Value & "','" & frm.Name & "', 'Wrong Password'" & "'" & frm.[passwordlogin].Value & "');"
'View evaluated statement in Immediate window.
Debug.Print strsql
DoCmd.SetWarnings False
DoCmd.RunSQL strsql
DoCmd.SetWarnings True
End Function
我在第一个编码中忘记的是添加''所以它可以被视为文本答案。*