Results 1 to 5 of 5
  1. #1
    netguy is offline Novice
    Windows 8 Access 2007
    Join Date
    Sep 2014
    Posts
    16

    Login Page

    Hey folks i need help with the following. I've created a simple log in form in access db. It authenticates against a user table with username and password. By default all passwords have been set as "password". After user tries to login i'd like them to change their password in the event it still ='s "password" If it does then close the current form, pass the username to form two and filter only on this user name. On form two I have included form field txtbox to allow the user to update their password. Here is the code I have so far.

    Here's where I need help:
    1) after receiving the message to update the password close the current form,
    2) pass user name as a variable to the second form
    3) open 2nd form and use variable in the where clause in the record source OR use the variable to filter all records OnLoad

    OnClick Event Form 1:


    Private Sub Command1_Click()
    If IsNull(Me.txtLoginID) Then
    MsgBox "Please enter LoginID!", vbInformation, "LoginID Required"
    Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter Password!", vbInformation, "Password Required"
    Me.txtPassword.SetFocus
    Else
    'process the job
    If (IsNull(DLookup("UserLogin", "tbl_users", "UserLogin ='" & Me.txtLoginID.Value & "'"))) Or _
    (IsNull(DLookup("Password", "tbl_users", "Password ='" & Me.txtPassword.Value & "'"))) Then


    MsgBox "Incorrect Login or Password"

    'ElseIf Me.txtPassword.Value = "password" Then
    ' MsgBox "Please change your password"
    ' DoCmd.Close


    Else
    DoCmd.Close
    DoCmd.OpenForm "MAIN"
    End If

    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If ... Then
    ...
    Else
    DoCmd.OpenForm "Main", , , "UserID=" & Me.txtLoginID
    End If
    End If
    DoCmd.Close acForm, "Login", acSaveNo
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    netguy is offline Novice
    Windows 8 Access 2007
    Join Date
    Sep 2014
    Posts
    16
    Ok so it still doesn't work. I get a prompt asking me to provide a parameter prior to loading the 2nd form
    Here is what I have so far;

    Form 1: Login
    ElseIf Me.txtPassword.Value = "password" Then
    MsgBox "Please change your password"
    DoCmd.OpenForm "frm_Login_update", , , "txtLoginID=" & Me.txtLoginID

    I'm assuming that the "txtLoginID" is the name Ill want to use when identfying the txt box on my next form

    Form 2: frm_Login_update
    Text Box - Name = txtLoginID and Source = UserLogin based on the SQL below
    Data tab - Record Source = SELECT tbl_users.UserLogin, tbl_users.Password FROM tbl_users;
    Filter = [txtLoginID]=[Forms]![Login].[txtLoginID]
    Filter OnLoad = Yes

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    No, the filter expression needs to reference field name, not textbox name, on the left side in quote marks.

    My suggested code passes filter criteria to the form when it is opened.

    I am confused. Your initial code does not use Filter property and it opened form Main. Why is this version referencing frm_Login_update and applying to Filter property?

    If you want to filter form after open by applying to Filter property, syntax - assuming UserID is a text field:

    Me.Filter = "UserID='" & [Forms]![Login].[txtLoginID] & "'"
    Me.FilterOn = True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    netguy is offline Novice
    Windows 8 Access 2007
    Join Date
    Sep 2014
    Posts
    16
    June1 The "Main" form was outside of the ELSE Statement and only ran if the two previous statement didn't . Here is the entire code that I now have working. Whats in bold is what I was looking for. Thank you!

    Private Sub Command1_Click()
    If IsNull(Me.txtLoginID) Then
    MsgBox "Please enter LoginID!", vbInformation, "LoginID Required"
    Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter Password!", vbInformation, "Password Required"
    Me.txtPassword.SetFocus
    Else
    'process the job
    If (IsNull(DLookup("UserLogin", "tbl_users", "UserLogin ='" & Me.txtLoginID.Value & "'"))) Or _
    (IsNull(DLookup("Password", "tbl_users", "Password ='" & Me.txtPassword.Value & "'"))) Then
    MsgBox "Incorrect Login or Password"

    ElseIf Me.txtPassword.Value = "password" Then
    MsgBox "Please change your password - " & Me.txtLoginID
    DoCmd.OpenForm "frm_Login_update", acNormal, , , , , "UserLogin=" & Me.txtLoginID
    Else
    DoCmd.Close
    DoCmd.OpenForm "MAIN"
    End If

    End If
    End Sub

    I then have another form page named frm_Login this page runs a stored procedure which uses [Forms]![Login]![txtLoginID] in the criteria of the SQL to find the reord matching txtLoginID

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

Similar Threads

  1. Replies: 10
    Last Post: 06-19-2014, 01:51 AM
  2. Login Page and Welcome note
    By annliang in forum Forms
    Replies: 3
    Last Post: 01-23-2014, 12:49 AM
  3. Replies: 1
    Last Post: 03-05-2013, 06:38 PM
  4. Creating Login Page from template
    By sherryb41 in forum Access
    Replies: 1
    Last Post: 01-31-2013, 03:10 PM
  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