Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    22

    Unanswered: Creating a Log In Screen

    I am trying to create a general Log In Screen for Access 2007 using VBA code. My front Form has been named frmLogIn. Within this form contains the two text fields txtUserName and txtPassword. I have a cmdClose button along with a cmdLogIn button. And if logged in successfully it goes to a Form called frmTrackingCosts So it looks like this:

    User Name: [txtUserName]
    Password: [txtPassword]

    cmdLogIn=[Log In] cmdClose=[Close]

    Now I have a table called tblLogIn within this table contains 2 fields one being UserName and the other is Password.

    Example of what my table shows:

    UserName Password
    Test ------------1
    Ray--------------red
    John-------------34

    How would I go about (using VBA) having a cmdLogIn button click event where when clicked it will go through the tblLogIn Table and find if the User Name that you typed and the password are in the table and if not let the User Know that.

    Here is what I have so far what am I missing????:
    Private Sub cmdLogIn_Click()

    If IsNull(Me.txtUserName) Or Me.txtUserName="" Then
    MsgBox "Please Make sure to fill in a User Name"
    End If

    If IsNull(Me.txtPassword) Or Me.txtPassword="" Then
    MsgBox "Please Make sure to fill in a Password"
    End If

    If Me.txtPassword.Value = DLookup("Password", "tblLogIn", [UserName] = """ & Me.UserName.Value & """) Then Then
    DoCmd.Close acForm, "frmLogIn", acSaveNo
    DoCmd.OpenForm "frmTrackingCosts"
    DoCmd.GoToControl "txtType"

    Else
    MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
    "Invalid Entry!"
    Me.txtPassword.SetFocus

    End If

    End Sub
    Whenever I click the Log In button it doesn't work it doesn't open the form and sometimes it changes what's in my Tables??? It's weird.
    Any helps is SUPER appreciated thanks guys!
    Last edited by DrewMan; 05-03-12 at 17:11.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Well, you didn't actually say what the problem is, but for starters your DLookup syntax is off:

    General: DLookup Usage Samples
    Paul

  3. #3
    Join Date
    Apr 2012
    Posts
    22
    The problem is when I run this code nothing works and it sometimes changes out my table and whatever you put in as the password it replaces the User Names password to the one that you type in.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Sounds like the form is bound to the table, which you probably don't want.
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •