Question
-
Topic
-
MS Access Login Forms
LockedDear friends,
I have a form which captures UserId and username from combo box and a ubound text box for password. Also i have a table which stores this details.
lngEmpID Autonumber
strEmpName text
strEmpPassword textI have a module called globals where i declare my public variables. I initialise my public variables in the login form on open procedure
Private Sub Form_Open(Cancel As Integer)
Me.cboEmployee.SetFocus
Init_Globals
End SubMy global module is listed below
Public Function Init_Globals()
WuserID = 0
Wuser = “”
End FunctionPublic Function Get_Global(gbl_parm)
Select Case gbl_parm
Case “WuserID”
Get_Global = WuserID
End Select
End FunctionIn the login form i have login button which after successful login i store the username in the public variable wuser. Below is the code for capturing use name to wuser variable.
Private Sub cboEmployee_AfterUpdate()
Me.txtPassword.SetFocus
WuserID = Me.cboEmployee
Wuser = Me.cboEmployee.Column(1)
End SubNow i would like to use this public variable to control all other functions of the database.
Since I have a swithboard for example if i want to view/edit records for certain engineer, the form will just filter only records which belongs to that engineer.I was able to achieve this when i was using currentuser() together with workground security table with the help of this code.
Public Sub Form_Current()
Dim User As String
Wuser = CurrentUser()
Wuser = UCase(Wuser)
If Wuser = “RN” Then
DoCmd.OpenForm “JobSystemcreation”, , , “projectcoordinator=’RN'”
ElseIf Wuser = “SM” Then
DoCmd.OpenForm “JobSystemcreation”, , , “projectcoordinator=’SM'”
ElseIf Wuser = “FI” Then
DoCmd.OpenForm “JobSystemcreation”
ElseIf Wuser = “SK” Then
DoCmd.OpenForm “JobSystemcreation”
End If
End SubPlease also note i have tried to substitute the open form command with the below code on a startup form which i later close .
DoCmd.OpenForm “JobsystemCreation”, , , “[Projectcoordinator]= ‘” & Wuser & ” ‘”Am sorry since i have made my question very long. It is because it has given me alot of headache.
With Regards,
J. Njoroge