Results 1 to 3 of 3
  1. #1
    RiceKnife is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    1

    Login form help

    Hello, Ive been trying to create a form where if the user inserts a username and password, the form will log in and send the user to another form. I searched around the internet for a while and I found a code that allowed me to this, but I do not understand it so can someone please explain it to me?

    Also how can I make it so that when the user opens the database the log in form popsup and does not let the user access any other part of the database until he/she has logged in?



    The Code:

    Private Sub cmdLogin_Click()
    On Error GoTo Err_cmdLogin_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim recSet As Recordset
    Dim isOK As Boolean
    Dim txUsername As String
    Dim txPassword As String

    Set recSet = CurrentDb.OpenRecordset("Login Credentials", dbOpenTable)

    txtusername.SetFocus
    txUsername = txtusername.Text
    txtpassword.SetFocus
    txPassword = txtpassword.Text

    With recSet
    Do While Not .EOF
    If txUsername = !UserName And txPassword = !Password Then isOK = True
    .MoveNext
    Loop
    End With
    If isOK = False Then MsgBox ("Invalid username/password!")
    If isOK = True Then
    stDocName = "Main"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If

    recSet.Close
    Exit_cmdLogin_Click:
    Exit Sub
    Err_cmdLogin_Click:
    MsgBox Err.Description
    Resume Exit_cmdLogin_Click
    End Sub

  2. #2
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    'sub procedure call.. runs but doesn't return a value
    Private Sub cmdLogin_Click()
    'if there are errors goto Err_cmdLogin_Click
    On Error GoTo Err_cmdLogin_Click
    'set the variables
    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim recSet As Recordset
    Dim isOK As Boolean
    Dim txUsername As String
    Dim txPassword As String

    'set the recordset to the table [Login Credentials]
    Set recSet = CurrentDb.OpenRecordset("Login Credentials", dbOpenTable)

    'put the cursor on txtusername not needed..
    txtusername.SetFocus
    txUsername = me.txtusername.Text
    'put the cursor on txt password not needed..
    txtpassword.SetFocus
    txPassword = Me.txtpassword.Text
    isOk = False
    'use recSet for each . so recSet.MoveNext = .moveNext
    With recSet
    'Loop thru all records
    Do While Not .EOF
    'if you find the username and Password.. say ok I would add this..
    If txUsername = !UserName And txPassword = !Password Then
    isOK = True
    exit Do 'exits the loop when the value is found.. otherwise you have to loop thru all records
    end if

    .MoveNext
    Loop
    End With
    'check to see if you found the right username and password..
    If isOK = False Then MsgBox ("Invalid username/password!")
    If isOK = True Then
    'if you find it then go to the main form.
    stDocName = "Main"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If
    'close the table
    recSet.Close
    'quit the sub procedure..
    Exit_cmdLogin_Click:
    Exit Sub
    'go here if you have an error..
    Err_cmdLogin_Click:

    MsgBox Err.Description
    Resume Exit_cmdLogin_Click
    End Sub

  3. #3
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    However if you are trying to prevent people from going anywhere you must make this a modal form and people can still hold the shift key down and get in by bypassing your form.

    You would have to write some vba code to prevent this as well. So I am not sure how far you want to go to make this bullet proof. You can make a mde file from your mdb file and this way they can't get to you code only forms..

    good luck

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

Similar Threads

  1. Login Form
    By greatopoo in forum Programming
    Replies: 1
    Last Post: 12-02-2012, 03:13 PM
  2. Login Form
    By data808 in forum Forms
    Replies: 1
    Last Post: 08-23-2012, 04:48 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