0

如标题所述,任何人都可以帮助我了解我在 Access 2013 上的表单登录。我只想为每个用户 ID 上的每次成功登录在我的用户名表(日期类型日期时间)上更新时间戳。另一个问题是我想为每 3 次登录失败锁定用户登录表单。

Private Sub CmdLogin_Click()

If IsNull(Me.cboNama) Or Me.cboNama = "" Then
    MsgBox "Please fill your username first!", vbOKOnly, "Input Username"
    Me.cboNama.SetFocus
     Exit Sub
End If

If IsNull(Me.txtPword) Or Me.txtPword = "" Then
    MsgBox "Please fill your password!", vbOKOnly, "Input Password"
    Me.txtPword.SetFocus
    Exit Sub
End If

If Me.txtPword.Value = DLookup("Password", "Ms_UserID", "[Password]='" &                 Me.txtPword.Value & "'") Then
    MyUserID = Me.cboNama.Value
    MsgBox "Login Success", vbOKOnly, "Message"
    'Me.Last_Login = DateTime()
    DoCmd.Close acForm, "Frm_Login", acSaveNo
    DoCmd.OpenForm "Ms_Userid"

    Else
    MsgBox "Wrong Username/Password!  Please specify your caps lock, Boss..", vbCritical, "Error Message"
    Me.txtPword.SetFocus
End If
End Sub
4

2 回答 2

0

这是我对 Click Button VBA 代码的最新修改,请看一下,因为仍然存在错误(出现弹出窗口并显示“输入参数值:Ms_Userid.timestamp”我应该手动输入 i 吗?因为我已经在使用= NOW() 函数。

非常感谢。!

Private Sub cmdLogin_Click()
Dim SQL As String

'Check mandatory fields
If IsNull(Me.cboNama.Value) Or Me.cboNama.Value = "" Then
   MsgBox "User ID is required.", vbOKOnly, "Required Data"
   Me.cboNama.SetFocus
   Exit Sub
End If

If IsNull(Me.txtPword.Value) Or Me.txtPword.Value = "" Then
   MsgBox "Password is required.", vbOKOnly, "Required Data"
   Me.txtPword.SetFocus
   Exit Sub
End If





SQL = "UPDATE Ms_Userid " & _
          "SET Ms_Userid.timestamp = Now()" & _
          "WHERE Ms_Userid.UserID = '&frms!Frm_Login!cboNama&'"





'Compare input password and database password
If Me.cboNama.Value <> "" Then
   If Me.txtPword.Value = DLookup("Password", "Ms_UserID", "[Password]='" & Me.txtPword.Value & "'") Then
      'MyUserID = Me.cboNama.Value
      'DoCmd.RunSQL "UPDATE Ms_Userid SET timestamp = Now() where UserID='" & frms!Frm_Login!cboNama & "';"
      DoCmd.RunSQL SQL
      'Close Login Page
      MsgBox "Login Success", vbOKOnly, "Message"
      DoCmd.Close acForm, "Frm_Login", acSaveNo
      DoCmd.OpenForm "Ms_Userid"
   Else
      MsgBox "Invalid Password. Try again.", vbOKOnly, "Invalid Entry!"
      Me.txtPword.SetFocus
   End If
End If

'If user enters incorrect password 3 times
intLoginAttempts = intLoginAttempts + 1
If intLoginAttempts = 3 Then
   MsgBox "You do not have access to the database. Please contact system administrator.", vbCritical, "Restricted Access!"
   Application.Quit
End If
End Sub
于 2013-08-12T02:27:39.697 回答
0

sql语句本质上是:

"UPDATE username SET thestamp = NOW() WHERE userid = " & frms!yourForm!txtUserID

您可以使用DoCmd.RunSql运行此 sql:

DoCmd.RunSql "the sql statement"

CurrentDb.Execute

在表单模块的顶部,您可以创建一个私有变量来计算尝试次数:

Private counter As Integer

它将默认为 0。然后单击一个按钮可以增加它counter = counter + 1

这根本不安全或万无一失。用户可以简单地关闭并重新打开表单。您可以将计数器存储在表格中,但同样,这很容易被覆盖。

added timestamp是 Access 中的保留字,需要用方括号括起来。

于 2013-08-01T17:14:18.490 回答