用户级MS Access 2010

时间:2017-01-31 06:39:03

标签: access-vba ms-access-2010

我使用此代码来保护我的登录,但我的密码有问题,例如我有两个用户名和两个密码...当我使用用户名时,两个密码都可以登录...任何人都可以帮忙...这里使用的代码...

 Private Sub cmdmsk_Click()
    Dim UserLevel As Integer
    Me.cmdmsk.SetFocus

    If IsNull(Me.txtuser) Then
        MsgBox "plis enter username", vbInformation, "Username needs to Login"
        Me.txtuser.SetFocus
    ElseIf IsNull(Me.txtpass) Then
        MsgBox "plis enter you password", vbInformation, "Password needs to login"
        Me.txtpass.SetFocus
    Else
        'process the job
        If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin ='" & Me.txtuser.Value & "'"))) Or _ 
      (IsNull(DLookup("Password", "tblUser", "Password ='" & Me.txtpass.Value & "'"))) Then
            MsgBox "wrong pass or username"
        Else


           UserLevel = DLookup("UserSecurity", "tblUser", "UserLogin = '" & Me.txtuser.Value & "'")



                     If UserLevel = "1" Then

                      MsgBox "Cangratulations ^_^"
                      DoCmd.Close
                      DoCmd.OpenForm "MENU"

                      Else


                      DoCmd.Close
                      DoCmd.OpenForm "INPUT"
            End If
            End If
            End If

    End Sub

1 个答案:

答案 0 :(得分:0)

只查看一下:

Private Sub cmdmsk_Click()

    Dim UserLevel As Variant

    Me!cmdmsk.SetFocus

    If IsNull(Me!txtuser.Value) Then
        MsgBox "Please enter your username.", vbInformation, "Missing Username"
        Me!txtuser.SetFocus
    ElseIf IsNull(Me!txtpass.Value) Then
        MsgBox "Please enter your password", vbInformation, "Missing Password"
        Me!txtpass.SetFocus
    Else
        'process the job
        UserLevel = DLookup("UserSecurity", "tblUser", _
            "[UserLogin] = '" & Me!txtuser.Value & "' And [Password] = '" & Me!txtpass.Value & "'")

        If IsNull(UserLevel) Then
            MsgBox "Incorrect username or password.", vbInformation, "Login"
        Else
            If UserLevel = "1" Then
                DoCmd.OpenForm "MENU"
            Else
                DoCmd.OpenForm "INPUT"
            End If
            DoCmd.Close
        End If
    End If

End Sub