Want to create a logon form with username and password from Access Form

Anyone out there have any examples that will help me create a form in Access where a user can enter there username and password to enter the database? I want to capture there username to be used later when creating reports as well..

Thanks in advance!
LVL 2
Jarred MeyerProduction ManagerAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
This should get you started:

http://www.databasedev.co.uk/login.html

mx
0
 
Jarred MeyerProduction ManagerAuthor Commented:
This is exactly what I'm looking for however, I cannot get passed a certain line in the code..

The entire code I'm using is;

Private Sub cmdLogon_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("EmpPassword", "tblEmployees", _
            "[EmpName]=" & Me.cboEmployee.Value) Then

        EmpName = Me.cboEmployee.Value

        'Close logon form and open splash screen

        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "frmSplash"

    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 admin.", _
               vbCritical, "Restricted Access!"
        Application.Quit
    End If

End Sub

Open in new window


It errors out at;

   If Me.txtPassword.Value = DLookup("EmpPassword", "tblEmployees", _
            "[EmpName]=" & Me.cboEmployee.Value) Then


And gives me the following error message;

 error
jmeyer is one of the user names..

Any ideas on this?
0
 
als315Connect With a Mentor Commented:
Try
If Me.txtPassword.Value = DLookup("EmpPassword", "tblEmployees", _
            "[EmpName]='" & Me.cboEmployee.Value & "'") Then
Me.cboEmployee.Value is text field, when in example it is numeric. Add single quote before and after Me.cboEmployee.Value
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"
It errors out at;

   If Me.txtPassword.Value = DLookup("EmpPassword", "tblEmployees", _
            "[EmpName]=" & Me.cboEmployee.Value) Then"

Use this:

   If Me.txtPassword = DLookup("EmpPassword", "tblEmployees",  "[EmpName]=" & Chr(34) & Me.cboEmployee & Chr(34) ) Then
0
 
Jarred MeyerProduction ManagerAuthor Commented:
als315.. That did the trick!

Thanks DatabaseMX.. That link was exactly what I was looking for!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You are welcome.  Shame on that site for having syntax errors ... !

0
 
Jarred MeyerProduction ManagerAuthor Commented:
Thanks Data.. I just posted another question on this asking how to store the username for later use.. I asked that along with this in the original question but figured it is a good question on its on since it can apply to a lot of different situations aside from just a login screen..

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_27516682.html 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.