Eliasgitau
IS-IT--Management
Dear Learned Friends,
I have a form to make the login to the application, the username is stored in a public variable.
Logging on the application will send the user to the menu form. The scenerio is. I have engineers who create records whom i would like them to be viewing their own jobs only and also have other users who should view all jobs and update various pages on the form. I have been using the workgroup security to control all this with the help of currentuser(). Since now I have several database it has become difficult to be switching from one security file to the other for the users. With memory variable i have been able to track (debug) the user name upto main menu(Swithboard). If i select any option on the menu it does not call the option,but if i use the workgroup security file with the help of currentuser() the operations are okay. Please find my codes below.
***Global module
Option Compare Database
Global Wuser As String
Global WuserID As Long
Option Explicit
Public Function Init_Globals()
WuserID = 0
Wuser = ""
End Function
Public Function Get_Global(gbl_parm)
Select Case gbl_parm
Case "WuserID"
Get_Global = WuserID
End Select
End Function
**** Form Login
Option Compare Database
Private intLogonAttempts As Integer
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
Init_Globals
End Sub
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
WuserID = Me.cboEmployee
Wuser = Me.cboEmployee.Column(1)
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
box
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
Wuser = Me.cboEmployee.Column(1)
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Switchboard", , , , , , Wuser
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
*****Form Startup
Public Sub Form_Current()
Wuser = Get_Global(Wuser)
If Wuser = "RN" Then
DoCmd.OpenForm "JobSystemcreation", , , "projectcoordinator" = Wuser
ElseIf Wuser = "DS" Then
DoCmd.OpenForm "JobSystemcreation"
ElseIf Wuser = "YS" Then
DoCmd.OpenForm "JobSystemcreation"
ElseIf Wuser = "ADMIN" Then
DoCmd.OpenForm "JobSystemcreation"
ElseIf Wuser = "MASTER" Then
DoCmd.OpenForm "JobSystemcreation"
ElseIf Wuser = "NJOROGE" Then
DoCmd.OpenForm "JobSystemcreation"
End If
End Sub
Private Sub Form_Load()
DoCmd.Close
End Sub
Thanks In Advance
Elias Gitau
I have a form to make the login to the application, the username is stored in a public variable.
Logging on the application will send the user to the menu form. The scenerio is. I have engineers who create records whom i would like them to be viewing their own jobs only and also have other users who should view all jobs and update various pages on the form. I have been using the workgroup security to control all this with the help of currentuser(). Since now I have several database it has become difficult to be switching from one security file to the other for the users. With memory variable i have been able to track (debug) the user name upto main menu(Swithboard). If i select any option on the menu it does not call the option,but if i use the workgroup security file with the help of currentuser() the operations are okay. Please find my codes below.
***Global module
Option Compare Database
Global Wuser As String
Global WuserID As Long
Option Explicit
Public Function Init_Globals()
WuserID = 0
Wuser = ""
End Function
Public Function Get_Global(gbl_parm)
Select Case gbl_parm
Case "WuserID"
Get_Global = WuserID
End Select
End Function
**** Form Login
Option Compare Database
Private intLogonAttempts As Integer
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
Init_Globals
End Sub
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
WuserID = Me.cboEmployee
Wuser = Me.cboEmployee.Column(1)
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
box
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
Wuser = Me.cboEmployee.Column(1)
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Switchboard", , , , , , Wuser
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
*****Form Startup
Public Sub Form_Current()
Wuser = Get_Global(Wuser)
If Wuser = "RN" Then
DoCmd.OpenForm "JobSystemcreation", , , "projectcoordinator" = Wuser
ElseIf Wuser = "DS" Then
DoCmd.OpenForm "JobSystemcreation"
ElseIf Wuser = "YS" Then
DoCmd.OpenForm "JobSystemcreation"
ElseIf Wuser = "ADMIN" Then
DoCmd.OpenForm "JobSystemcreation"
ElseIf Wuser = "MASTER" Then
DoCmd.OpenForm "JobSystemcreation"
ElseIf Wuser = "NJOROGE" Then
DoCmd.OpenForm "JobSystemcreation"
End If
End Sub
Private Sub Form_Load()
DoCmd.Close
End Sub
Thanks In Advance
Elias Gitau