VBA代码在一个访问数据库中起作用,但不能在另一个访问数据库中工作。所有支持对象都已导入。我没有看到什么?

发布于 2025-01-25 15:20:59 字数 2641 浏览 2 评论 0原文

此代码适用于我设置的登录表单,以输入数据库的前端副本。在一个数据库中,它像魅力一样工作。我将表单和相应的对象导入了另一个数据库,并且在输入它时似乎没有识别我的密码。我只是继续弹出的消息框,上面写着“不正确的密码”。弄清楚这一点的任何帮助都将得到极大的赞赏。

在登录表单上驱动cbouser组合框的SQL语句是:

SELECT tblUser.UserID, [FName] & " " & [LName] AS Fullname, 
       tblUser.Password, tblUser.PWReset, tblUser.AccessLevelID 
FROM tblUser ORDER BY tblUser.LName, tblUser.FName;  

Private Sub OkBTN_Click()
    Static intIncorrectCount As Integer
    Dim AuthorityNumber As Integer
    'Dim rs         As Recordset
    
    'TempVars("Username") = Me.cboUser.Value
    
    'Column references for cbouser row source reference
    'UserID = 0
    'FullName = 1
    'Password = 2
    'PWReset = 3
    'AccessLevelID = 4
    
    'Set rs = CurrentDb.OpenRecordset("UserNameQuery", dbOpenSnapshot)
    
    'N = Nz(DLookup("Fullname", "UserNameQuery", "Fullname=""" & Me.cboUser & """"), " ")
    
    'Check that User is selected
    If IsNull(Me.cboUser) Then
        MsgBox "You forgot To Select your name from the drop down menu!", vbCritical
        Me.cboUser.SetFocus
    Else
        'Check for correct password
        If Me.txtPassword = Me.cboUser.Column(2) Then
            
            'Check if password needs to be reset
            If Me.cboUser.Column(3) Then
                DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            End If
            
            Me.Visible = FALSE
            intIncorrectCount = 0
            
            'Main menu after correct login based on AuthorityNumber
            If Me.cboUser.Column(4) = 5 Then
                DoCmd.OpenForm "SRL1MainMenu"
                'Forms!AMSReportForm!L2Menubtn.Visible = False
                Forms!SRL1MainMenu!FullNameLoggedIn = Forms!frmLogin!cboUser.Column(1)
            Else
                DoCmd.OpenForm "L2MainMenu2"
                'Forms!AMSReportForm!L2Menubtn.Visible = True
                Forms!L2MainMenu2!FullNameLoggedIn = Forms!frmLogin!cboUser.Column(1)
            End If
            
            'Failed login attempt limitation
        ElseIf intIncorrectCount > 1 Then
            MsgBox "Too many failed login attempts. Click OK To Set New password", vbOK + vbExclamation
            DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            'DoCmd.Close acForm, "frmLogin"
        Else
            MsgBox "Incorrect password", vbOKOnly + vbExclamation
            
            Me.txtPassword = Null
            Me.txtPassword.SetFocus
            intIncorrectCount = intIncorrectCount + 1
        End If
    End If
    
End Sub

This code is for a login form I have setup to enter the front end copy of a database. In one database it works like a charm. I imported the form and corresponding objects to another database and it appears to be not recognizing my password when I enter it. I just keep getting the message box I have popping up that says, "Incorrect password". Any help figuring this out would be greatly apprecaited.

The SQL statement that drives the cboUser combo box on the login form is:

SELECT tblUser.UserID, [FName] & " " & [LName] AS Fullname, 
       tblUser.Password, tblUser.PWReset, tblUser.AccessLevelID 
FROM tblUser ORDER BY tblUser.LName, tblUser.FName;  

.

Private Sub OkBTN_Click()
    Static intIncorrectCount As Integer
    Dim AuthorityNumber As Integer
    'Dim rs         As Recordset
    
    'TempVars("Username") = Me.cboUser.Value
    
    'Column references for cbouser row source reference
    'UserID = 0
    'FullName = 1
    'Password = 2
    'PWReset = 3
    'AccessLevelID = 4
    
    'Set rs = CurrentDb.OpenRecordset("UserNameQuery", dbOpenSnapshot)
    
    'N = Nz(DLookup("Fullname", "UserNameQuery", "Fullname=""" & Me.cboUser & """"), " ")
    
    'Check that User is selected
    If IsNull(Me.cboUser) Then
        MsgBox "You forgot To Select your name from the drop down menu!", vbCritical
        Me.cboUser.SetFocus
    Else
        'Check for correct password
        If Me.txtPassword = Me.cboUser.Column(2) Then
            
            'Check if password needs to be reset
            If Me.cboUser.Column(3) Then
                DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            End If
            
            Me.Visible = FALSE
            intIncorrectCount = 0
            
            'Main menu after correct login based on AuthorityNumber
            If Me.cboUser.Column(4) = 5 Then
                DoCmd.OpenForm "SRL1MainMenu"
                'Forms!AMSReportForm!L2Menubtn.Visible = False
                Forms!SRL1MainMenu!FullNameLoggedIn = Forms!frmLogin!cboUser.Column(1)
            Else
                DoCmd.OpenForm "L2MainMenu2"
                'Forms!AMSReportForm!L2Menubtn.Visible = True
                Forms!L2MainMenu2!FullNameLoggedIn = Forms!frmLogin!cboUser.Column(1)
            End If
            
            'Failed login attempt limitation
        ElseIf intIncorrectCount > 1 Then
            MsgBox "Too many failed login attempts. Click OK To Set New password", vbOK + vbExclamation
            DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            'DoCmd.Close acForm, "frmLogin"
        Else
            MsgBox "Incorrect password", vbOKOnly + vbExclamation
            
            Me.txtPassword = Null
            Me.txtPassword.SetFocus
            intIncorrectCount = intIncorrectCount + 1
        End If
    End If
    
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁对谁错谁最难过 2025-02-01 15:20:59

首先, @andre可能是正确的 - 您可能必须将括号应用于“密码”。

接下来,这可能不会执行案例敏感的比较:

If Me.txtPassword = Me.cboUser.Column(2) Then

使用strcomp这样做:

If StrComp(Me!txtPassword.Value, Me!cboUser.Column(2), vbBinaryCompare) = 0 Then

最后,您绝不应该存储普通密码;代替存储哈希值。这并不困难,如果您研究我的最新文章:

使用Microsoft ng ng加密(CNG)API 存储在VBA中存储密码

First, @Andre is probably right - you may have to apply brackets to "Password".

Next, this may not perform a case sensitive comparison:

If Me.txtPassword = Me.cboUser.Column(2) Then

Use StrComp to do that:

If StrComp(Me!txtPassword.Value, Me!cboUser.Column(2), vbBinaryCompare) = 0 Then

Finally, you should never store plain passwords; store a hash value instead. It isn't that difficult, if you study my latest article:

Storing passwords in VBA using the Microsoft NG Cryptography (CNG) API

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文