Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User from logging in 1

Status
Not open for further replies.

DarkOne72

Technical User
Jun 14, 2002
208
0
0
US
Hi all,

I am in need of help; I built a login form with a drop down list showing the names that I want to log in. The names are listed in a table cal tblEmployees. Everything works fine and they are able to log in but what I need to happen now is that when they are on a form it shows their name (no the computer user but the one who logged in database) so i can capture if they make any changes and also they kow who is logged in.
Below is the code that works for them to log in, i just don't know how to pass their name on to forms etc:

Code:
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.txtAccess.Value = DLookup("strAccess", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
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 forms
    If Me.txtAccess.Value = "Admin" Then
        DoCmd.Close acForm, "frmLogon", acSaveNo
         DoCmd.OpenForm "Switchboard"
        
            ElseIf Me.txtAccess.Value = "User" Then
                DoCmd.Close acForm, "frmLogon", acSaveNo
                DoCmd.OpenForm "User_Switchboard"
            End If

        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


Thanks in advance
 
I don't see where [blue]lngMyEmpID[/blue] is defined. If you make it a Public in the General Declarations section of a module then it will be available throughout the project.
 
where would I add that to this code up top ?

Sorry kinda new to this.
 
I assume that somewhere the variable [blue]lngMyEmpID[/blue] is defined. If it isn't then you should really have [blue]Option Explicit[/blue] as the first statement in every form, module etc. That prevents dynamic creation of variable names and requires that every variable be explicitly defined.

You would not define [blue]lngMyEmpID[/blue] in the form. Create a module and, after the [blue]Option Explicit[/blue] statement
Code:
Public lngMyEmpID As String
Make sure to delete the [blue]Dim lngMyEmpID ...[/blue] statement from where ever you have it. If you don't that will create a local instance of the variable and hide the Public one.

In any form where you want the Employee ID to appear
Code:
Me.SomeControl = lngMyEmpID
will display your employee ID.
 
Well, I did what you said and made sure the were no Dims anywhere containg the lngMyEmpID and on the form I still get #Name?

hmm...I will keep trying..thank you for all your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top