2017-01-31 2 views
0

Я использовал этот код для защиты моего входа в систему, но у меня была проблема с паролем, например, у меня есть два имени пользователя и два пароля ... когда я пользовался Имя пользователя и пароль могут войти в систему ... может кто-нибудь помочь ... вот код я использовал ...Пользовательский уровень 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 

ответ

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 
+0

Спасибо работает @Gustav – RPM

Смежные вопросы