Results 1 to 3 of 3
  1. #1
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142

    Login Form

    Re: https://www.accessforums.net/tutoria...een-43252.html
    I followed the tutorial from XIPooo on creating a classic Log in form, below is the code I wrote:

    Option Compare Database
    Option Explicit

    Private Sub btnLogin_Click()
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("LogIn_tbl", dbOpenSnapshot, dbReadOnly)
    rs.FindFirst "UserName='" & Me.txtUserName & "'"
    If rs.NoMatch = True Then
    Me.lblwronguser.Visible = True
    Me.txtUserName.SetFocus
    Exit Sub
    End If

    Me.lblwronguser.Visible = False

    If rs!Password <> Me.txtPassword Then
    Me.lblwrongpassword.Visible = True
    Me.txtPassword.SetFocus
    Exit Sub
    End If

    Me.lblwrongpassword.Visible = False



    DoCmd.Close acForm, "LogIn_frm"
    DoCmd.OpenForm "Home_frm"
    End Sub

    The problem I have when I enter a wrong user name it works fine, however when I hit enter or click the Log In Button after entering the correct user name it skips the password entry and closes the form without a password. The tutorial was shown for 2013 I am running 2010 is there a difference in programming?

    Or I have I coded the second part of the routine wrong???
    Last edited by June7; 08-03-2014 at 06:42 PM.

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    I posted a DEMO in Sample Databases.

    HTH

  3. #3
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Quote Originally Posted by Derrick T. Davidson View Post
    I followed the tutorial from XIPooo on creating a classic Log in form, below is the code I wrote:

    Option Compare Database
    Option Explicit

    Private Sub btnLogin_Click()
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("LogIn_tbl", dbOpenSnapshot, dbReadOnly)
    rs.FindFirst "UserName='" & Me.txtUserName & "'"
    If rs.NoMatch = True Then
    Me.lblwronguser.Visible = True
    Me.txtUserName.SetFocus
    Exit Sub
    End If

    Me.lblwronguser.Visible = False

    If rs!Password <> Me.txtPassword Then
    Me.lblwrongpassword.Visible = True
    Me.txtPassword.SetFocus
    Exit Sub
    End If

    Me.lblwrongpassword.Visible = False

    DoCmd.Close acForm, "LogIn_frm"
    DoCmd.OpenForm "Home_frm"
    End Sub

    The problem I have when I enter a wrong user name it works fine, however when I hit enter or click the Log In Button after entering the correct user name it skips the password entry and closes the form without a password. The tutorial was shown for 2013 I am running 2010 is there a difference in programming?

    Or I have I coded the second part of the routine wrong???
    You might want to have a look at the sample code I posted for the login.

    https://drive.google.com/folderview?...UtXRmJ1VS1yQUU

    Here's the code from that sample code:
    Code:
    Private Sub btnLogin_Click()    
        Dim rs As Recordset
        
        Set rs = CurrentDb.OpenRecordset("tbl1Employees", dbOpenSnapshot, dbReadOnly)
        
        rs.FindFirst "UserName='" & Me.txtUserName & "'"
        
        If rs.NoMatch Then
            Me.lblWrongUser.Visible = True
            Me.txtUserName.SetFocus
            Exit Sub
        End If
        Me.lblWrongUser.Visible = False
        
        If rs!Password <> Me.txtPassword Then
            Me.lblWrongPass.Visible = True
            Me.txtPassword.SetFocus
            Exit Sub
        End If
        Me.lblWrongPass.Visible = False
        DoCmd.OpenForm "frmMain"
        DoCmd.Close acForm, Me.Name
    End Sub
    It looks like you are closing the form before opening the new form. Closing the form will cause the code to stop at that point.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-17-2014, 10:23 AM
  2. Login Form
    By greatopoo in forum Programming
    Replies: 1
    Last Post: 12-02-2012, 03:13 PM
  3. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  4. Login form with nt login
    By hitesh_asrani_j in forum Forms
    Replies: 6
    Last Post: 09-22-2011, 11:43 AM
  5. Login Form
    By Kookai in forum Access
    Replies: 3
    Last Post: 10-18-2010, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums