Results 1 to 3 of 3
  1. #1
    darkdemon is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Posts
    13

    Change password using tempvar not passing to following form

    Okay I have a login form and when the temporary password is set to "Password" for a new user, the new user logs in and then it should direct them to change their password upon first login. So on the login form I have this code set on the login button:
    Code:
    Private Sub cmd_login_Click()
    Dim FIRST_NAME As Variant, access_level As Variant, user As Variant
    Dim TempPass As String
    
    If Trim(Me.txt_username.Value & vbNullString) = vbNullString Then
        MsgBox prompt:="Username required.", buttons:=vbExclamation, title:="Information"
        Me.txt_username.SetFocus
    Exit Sub
    End If
    
    If Trim(Me.txt_password.Value & vbNullString) = vbNullString Then
        MsgBox prompt:="Password required.", buttons:=vbExclamation, title:="Information"
        Me.txt_password.SetFocus
    Exit Sub
    End If
    
    ' RETREIVE FROM SAVED QUERY
    ' ASSUMES EVERY USER GIVEN A NON-NULL ACCESS LEVEL
    FIRST_NAME = DLookup("FirstName", "tbl_login", "UserName = '" & Me.txt_username & "' and password = '" & Me.txt_password & "'")
    access_level = DLookup("access_level", "tbl_login", "UserName = '" & Me.txt_username & "' and password = '" & Me.txt_password & "'")
    
    If IsNull(FIRST_NAME) = True Then
        MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, title:="Information"
        Me.txt_username.SetFocus
    Else
        MsgBox prompt:="Welcome, " & FIRST_NAME & ".", buttons:=vbOKOnly, title:="to the QAE System"
    
    TempPass = DLookup("[Password]", "tbl_Login", "UserName='" & Me.txt_username.Value & "'")
        If (TempPass = "Password") Then
            DoCmd.OpenForm "frm_ChangePassword", acNormal, "", "", , acWindowNormal
            GoTo Done
        End If
      
    'save the first_name and access_level to Tempvars
    TempVars("First_Name") = FIRST_NAME
    TempVars("Access_Level") = access_level
    TempVars("user") = Me.txt_username.Value
      
    ' CONDITIONALLY OPEN FORMS
    Select Case access_level
    Case "Admin"
        DoCmd.OpenForm "frm_Admin"
        DoCmd.Close acForm, "frm_login", acSaveNo
            
    
    Case "User"
        DoCmd.OpenForm "frm_User"
        DoCmd.Close acForm, "frm_login", acSaveNo
    End Select
    End If
    Done:
        DoCmd.Close acForm, "frm_login", acSaveNo
    End Sub
    When a user logs in with user name and password if their password is set
    to anything other than "Password" it displays their first name
    correctly on the following form. This code is on that following form and
    it works really well:
    Code:
    Private Sub Form_Load()
        Me.Text325 = TempVars("First_Name").Value & ""
    End Sub
    I also have a button on that form if the user wants to change their
    password and the First name carries over without an issue. However, my
    problem is when their password is set to "Password" requiring a first
    time login password change it is not displaying. This is the code on


    that password change form:

    Code:
    Private Sub Form_Load()
        Me.Text337 = TempVars("First_Name").Value & ""
    End Sub

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2021
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    I can't see where the code sets any tempvar before it opens frm_ChangePassword
    Last edited by davegri; 11-22-2024 at 10:57 AM. Reason: mod

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 2
    Last Post: 02-06-2019, 09:16 AM
  2. Insert into field Tempvar using query
    By jaryszek in forum Access
    Replies: 7
    Last Post: 11-22-2017, 01:31 PM
  3. Replies: 7
    Last Post: 04-29-2015, 10:57 AM
  4. Replies: 1
    Last Post: 06-22-2012, 08:05 AM
  5. Replies: 7
    Last Post: 10-27-2010, 12:02 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