Hello,
I've been trying to follow total to create login system mentioned on this link. I'm saving access level in a string strAcsLvl. 0 means no user is logged in whole 1 is for developer, 2 for administrator (except 0 value, other AccessLevelID are picked from tblUser.) I've modified the code as below
I've placed following code in the form update event of the form where cmdLogin is created to open a login form so that when strAcsLvl value is zero, it should show caption of button as Login otherwise Logout.
Now problem I'm facing is, even though I defined strAcsLvl as global variable but when login form is closed and I reopen my form on which cmdLogin is placed, it still shows Login which does that strAcsLvl is cleared or has not retained the AccessLevelID in it. I am new to Access and don't where I'm doing wrong. Kindly help.
Best Regards,
Abdullah
I've been trying to follow total to create login system mentioned on this link. I'm saving access level in a string strAcsLvl. 0 means no user is logged in whole 1 is for developer, 2 for administrator (except 0 value, other AccessLevelID are picked from tblUser.) I've modified the code as below
Rich (BB code):
Option Compare Database
Dim strAcsLvl As String
Private Sub txtPassword_AfterUpdate()
'Check that EE is selected
If IsNull(Me.cboUser) Then
MsgBox "You need to select a user!", 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) = True Then
DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
End If
If DLookup("[AccessLevelID]", "tblUser", "[UserID] = " & Forms!frmLogin!cboUser) = 1 Then
SetProperties "AllowBypassKey", dbBoolean, True
MsgBox "Developer access verified. Hold shift key while opening the app to open as developer."
DoCmd.Close
DoCmd.Quit acQuitSaveAll
End If
'DoCmd.OpenForm "frmMainMenu"
strAcsLvl = Nz((DLookup("[AccessLevelID]", "tblUser", "[UserID] = " & Forms!frmLogin!cboUser)), 0)
Forms![frmMore]![cmdLogin].Caption = "Logout"
DoCmd.Close
Else
MsgBox "Password does not match, please re-enter!", vboOkOnly
Me.txtPassword = Null
Me.txtPassword.SetFocus
End If
End If
End Sub
I've placed following code in the form update event of the form where cmdLogin is created to open a login form so that when strAcsLvl value is zero, it should show caption of button as Login otherwise Logout.
Rich (BB code):
Private Sub Form_Load()
If strAcsLvl = 0 Then
Me.cmdLogin.Caption = "Login"
Else
Me.cmdLogin.Caption = "Logout"
End If
End Sub
Now problem I'm facing is, even though I defined strAcsLvl as global variable but when login form is closed and I reopen my form on which cmdLogin is placed, it still shows Login which does that strAcsLvl is cleared or has not retained the AccessLevelID in it. I am new to Access and don't where I'm doing wrong. Kindly help.
Best Regards,
Abdullah