Results 1 to 11 of 11
  1. #1
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36

    Help with Login Form

    Hi all,

    I have created a Login form that opens as soon as my database opens.
    the username and the password textboxes both work they accept the username and the password but my problem is that each time I login it keeps adding my login name and password to my table.

    tested 4 times then went into my table and there was my username and password 4 times, any ideas what is going


    on below is the code I'm using.

    Thanks for any help in advance
    Appologise now I think I just posted this in the wrong place. sorry

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub btnLogin_Click()
        Dim rs As Recordset
       
        Set rs = CurrentDb.OpenRecordset("tblLogin", 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.lblWrongPass.Visible = True
            Me.txtPassword.SetFocus
        Exit Sub
    End If
    Me.lblWrongPass.Visible = False
    DoCmd.OpenForm "frmNavigation"
    DoCmd.Close acForm, Me.Name
    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    What are you using to determine the value of Me.txtUsername?

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Is tblLogin the record source for this form? That might be where the records are being added each time you open the form.

  4. #4
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36
    hi and thankyou for your replies,
    Yes the table called tblLogin is where the username and passwords are stored.
    and I'm not sure ItsMe what you mean by determining the value of me.txtusername. in its properties it's control source is in tblLogin, field called UserName. same with the password its control source is password. The form its self is set to control source tblLogin.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    the point I am trying to get at is you need to locate a record within the table that matches, Joe, Sue, or Bob. What your code seems to be doing is matching a record in the table that matches the Current Record of the Form's Recordset.

    So, if you open the bound form and the record it opens to is Joe, your code is doing something like ...

    Open recordset of table

    Find first record that = Joe

    If record no match then
    Deal with it and exit sub

    hide lblWronguser

    If the Joe's password <> txtUsername
    Then deal with it and exit sub

    Show lblWrongPass
    Allow access to other form

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Removing the table as the form's record source will stop the duplicate records being added. Or else do it ItsMe's method.

  7. #7
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36
    thanks for the reply ItsMe,
    ill look over everything ive done and double check.
    and if I remove the record source from the form aytee111 I can no longer enter any data into the textboxes
    so I just have to go over it all and find the problem I guess

  8. #8
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Your textboxes will be known as "unbound" textboxes, i.e. not bound to a record source, with empty Control Source property. In your code above you are validating the entries thru the back-end, not using the form for verification. It would be simpler to make it an unbound form and control the reading of the tables thru your code (as you have it above).

  9. #9
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36
    hi aytee111

    I removed sources from my textboxes and my form, my textboxes are unbound, the problem I have is that when I got to form view I can click inside the textboxes but I can not type anything into these boxes.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Remove the RecordSource from the form. Add a combobox to replace the UserName textbox control. Use the table as the RowSource of the combo. Use the correct column to Store the Value For Later Use.

    Use the Value property of your combo in your VBA
    Code:
    rs.FindFirst "UserName='" & Me.ComboboxName.Value & "'"
    That should be a start to fix a few problems.

  11. #11
    Gregm66 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    36
    Hi ItsMe

    Thanks for you reply and input I checked all of my properties for my form, the following settings were all set to no I changed to yes and now the form works as it should.

    Data Entry was no
    Allow additions was no
    Allow deletions was no
    Allow edits was no

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

Similar Threads

  1. Replies: 4
    Last Post: 07-17-2015, 10:04 AM
  2. Replies: 2
    Last Post: 04-17-2015, 10:59 AM
  3. Replies: 3
    Last Post: 03-17-2014, 10:23 AM
  4. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  5. Login form with nt login
    By hitesh_asrani_j in forum Forms
    Replies: 6
    Last Post: 09-22-2011, 11:43 AM

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