Login form help

richard05

Registered User.
Local time
Today, 06:18
Joined
Mar 18, 2009
Messages
10
Basically I have used a login template that was off the internet, I am trying to alter so different form opens per different user

such as the admin will go straight to the main menu page (which is currently at now for all users as can see from code below) and then for a lower level user it will just open one particular form ("capital expenditure form") so that they can't view any other forms.

Was wondering if anyone is able to guide me on what to do

Code:
Option Compare Database
Private intLogonAttempts As Integer
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
End Sub
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo 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
'Check to see if data is entered into the password box
    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
            MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
        Exit Sub
    End If
'Check value of password in tblEmployees to see if this matches value chosen in combo box
    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
        lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
        
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "Main Menu"
        Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If
    
'If User Enters incorrect password 3 times database will shutdown
    
    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
 
Code:
DoCmd.OpenForm "Main Menu"

Instead of this, use a Case Select.

Also, instead of this

Code:
DoCmd.Close acForm, "frmLogon", acSaveNo

you may want this

Code:
me.frmlogon.properties.hidden=true

This way the logon form stays open, and you can refer to the user who is logged in in other parts of your db if you need to. Also, the combo that returns the username, you may want other relevant fields to be in that drop down box with a zero width. Makes it easy to refer to the current user.
 
Last edited:
When you mention case select, am I suppose to lay as shown below, (not to familiar with case select)

Code:
DoCmd.Close acForm, "frmLogon", acSaveNo
        Select Case employee
        Case Richard
            DoCmd.OpenForm "Main Menu"
        Case John
            DoCmd.OpenForm "Capital Expenditure"
        End Select
 
Last edited:
Select case is your [Expression] so maybe:

Dim stDocName As String
Select Case Me.cboEmployee

Case "Richard"
stDocName = "Main_Menu"
DoCmd.OpenForm stDocName, acNormal

End Select

Assuming that the Case Select is going to be contained in the body of code for the password check.

good luck John
 
Heres how I have done it before.

Code:
Dim strAccessLevel As String
Dim strForm As String
strAccessLevel = Nz(DLookup("UserTypeID", "tblEmployee", "[EmployeeID]=" & Me.cboLogin.Value), "4")
                    
                           Select Case strAccessLevel
                           
                           Case 1
                           strForm = "frmHome"
                           Case 2
                           strForm = "frmHomeOperator"
                           Case 3
                           strForm = "frmHomeManager"
                           Case 4
                           strForm = "frmHomeUser"
                           End Select
                           Me.Visible = False
                           DoCmd.OpenForm strForm
                           Me.Visible = False
                           End If

If your username combo box brings user type, then you can do the strAccessLevel part differently. It might look like this instead

Code:
strAccessLevel=me.usernamecombobox.column(n)
 
Doh!!! forgot the bound field of the Combo box probably not the employees name....
 

Users who are viewing this thread

Back
Top Bottom