用户级别 MS 访问 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

只查一下:

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

最新更新