按钮可以检查密码和过滤器吗?

问题描述 投票:0回答:1

很抱歉打扰你了...我正在尝试创建一个登录页面,在输入正确的用户名和密码后,它会过滤下面的子表单,以便他们只能看到他们的评论。我有它,所以有两个按钮,其中一个通过VBA代码检查用户名和密码,另一个按钮使用宏过滤...但我想一个按钮做所有事情,以便如果密码不正确,那么他们不能什么都看见过滤器按钮目前无需密码即可使用,只要有正确的用户名,它就会在不查看密码的情况下对其进行过滤。

Option Compare Database
Option Explicit

Private Sub btnLogin_Click()
    Dim rs As Recordset

        Set rs = CurrentDb.OpenRecordset("tbl1Employees", dbOpenSnapshot, dbReadOnly)

    rs.FindFirst "UserName='" & Me.txtUserName & "'"

    If rs.NoMatch Then
        Me.lblWrongUser.Visible = True
        Me.txtUserName.SetFocus
        Exit Sub
    End If
    Me.lblWrongUser.Visible = False

    If rs!Password <> Nz(Me.txtPassword, "") Then
        Me.lblWrongPass.Visible = True
        Me.txtPassword.SetFocus
        Exit Sub
    End If
    Me.lblWrongPass.Visible = False


    Dim search_text As String
    search_text = Me.txtUserName

        If Nz(Me.txtUserName.Value, "") = "" Then
    Me.FilterOn = False
    Me.txtUserName.SetFocus
    Exit Sub
End If
Me.Filter = "UserName like '*" & Me.txtUserName.Value & "*' or userName like '*"
Me.FilterOn = True
Me.txtUserName.SetFocus
Me.txtUserName.Value = search_text
Me.txtUserName.SelStart = Len(Nz(Me.txtUserName. Value, "")) & 1

End Sub
ms-access access-vba
1个回答
0
投票

我决定只创建一个宏并在代码的末尾运行一个docmd运行宏:)谢谢大家

© www.soinside.com 2019 - 2024. All rights reserved.