Results 1 to 9 of 9
  1. #1
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164

    Welcome Back "Text box message" of the user who has just logged in

    Hi,



    I have borrowed some code from a users database for a login form.

    This works fine using VBA, checks the user against the password (dgodkin - Password etc)

    The same record in the table also stores the full name of first name and last name fields (Darren Godkin) and site bakery.

    I would like to combine first and last names and have it display in a text box welcome style message on my first form as the user passes validation on the login.

    Can anyone suggest any ideas as I am a newbie but willing to learn.

    I tried the Tempvars approach but the usernames are first letter of forename and last name. (This does not help in getting the Bakery field either)

    I'm not sure how to adapt the code to make this happen.

    Click image for larger version. 

Name:	DS7.jpg 
Views:	8 
Size:	135.1 KB 
ID:	20744Click image for larger version. 

Name:	DS8.jpg 
Views:	8 
Size:	112.0 KB 
ID:	20745

  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,815
    We need to see code for analysis.

    Why didn't TempVars work? Why is the username structure an issue?
    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
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164
    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 <> Encrypt(Me.txtPassword) Then
    Me.lblWrongPass.Visible = True
    Me.txtPassword.SetFocus
    Exit Sub
    End If
    Me.lblWrongPass.Visible = False

    TempVars("UserName").value = Me.txtUserName.value

    If rs!EmployeeType_ID = 3 Then
    Dim prop As Property
    On Error GoTo SetProperty
    Set prop = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)

    CurrentDb.Properties.Append prop

    SetProperty:
    If MsgBox("Would you like to turn on the Bypass Key?", vbYesNo, "Allow Bypass?") = vbYes Then
    CurrentDb.Properties("AllowBypassKey") = True
    Else
    CurrentDb.Properties("AllowBypassKey") = False
    End If
    End If

    Me.Visible = False
    Globals.Logging "Logon"

    DoCmd.OpenForm "frmMainMenu"
    ' DoCmd.Close acForm, Me.Name

  4. #4
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164
    Click image for larger version. 

Name:	DS9.jpg 
Views:	8 
Size:	114.6 KB 
ID:	20746

    The Tempvars kinda works but stays highlighted on the screen, I want the full name of the user and not highlighted on the form load.

    thanks

    Darren

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Please post code within code tags to retain indentation and will be more readable.

    Set TempVar to the concatenated first and last names if that's what you really want to pass.

    = rs!FirstName & " " & rs!LastName
    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.

  6. #6
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164
    '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 <> Encrypt(Me.txtPassword) Then
    ' Me.lblWrongPass.Visible = True
    ' Me.txtPassword.SetFocus
    ' Exit Sub
    ' End If
    ' Me.lblWrongPass.Visible = False
    '
    ' TempVars("UserName").value = Me.txtUserName.value
    '
    ' If rs!EmployeeType_ID = 3 Then
    ' Dim prop As Property
    ' On Error GoTo SetProperty
    ' Set prop = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)
    '
    ' CurrentDb.Properties.Append prop
    '
    'SetProperty:
    ' If MsgBox("Would you like to turn on the Bypass Key?", vbYesNo, "Allow Bypass?") = vbYes Then
    ' CurrentDb.Properties("AllowBypassKey") = True
    ' Else
    ' CurrentDb.Properties("AllowBypassKey") = False
    ' End If
    ' End If
    '
    ' Me.Visible = False
    ' Globals.Logging "Logon"
    '
    ' DoCmd.OpenForm "frmMainMenu"
    '' DoCmd.Close acForm, Me.Name




    End Sub

  7. #7
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164
    Sorry, Is that better and more readable?

    Thanks for your help again June7, Much apreciated!

    I made a textbox and entered into the box : =TempVars("UserName").[Value]

    That worked but if you see my screenshot above, the dgodkin username stays selected/highlighted.

    I would much prefer the full name value pulled out of the record of the user who logs in, I not sure how to write the code or ammend what I already have to:

    Set TempVar to the concatenated first and last names if that's what you really want to pass.

    = rs!FirstName & " " & rs!LastName

    I get your logic though and that is what i want to acheive.

    thanks

    again
    = rs!FirstName & " " & rs!LastName

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    No, not within code tags. Copy code from VBA, click the CODE button on the post editor menu, paste code.

    Just change the right hand side of the expression that sets TempVar.
    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.

  9. #9
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164
    Code:
    Private Sub btnClose_Click()    DoCmd.Quit
    End Sub
    
    
    '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 <> Encrypt(Me.txtPassword) Then
    '        Me.lblWrongPass.Visible = True
    '        Me.txtPassword.SetFocus
    '        Exit Sub
    '    End If
    '    Me.lblWrongPass.Visible = False
    '
    '    TempVars("UserName").value = Me.txtUserName.value
    '
    '    If rs!EmployeeType_ID = 3 Then
    '        Dim prop As Property
    '        On Error GoTo SetProperty
    '        Set prop = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)
    '
    '        CurrentDb.Properties.Append prop
    '
    'SetProperty:
    '        If MsgBox("Would you like to turn on the Bypass Key?", vbYesNo, "Allow Bypass?") = vbYes Then
    '            CurrentDb.Properties("AllowBypassKey") = True
    '        Else
    '            CurrentDb.Properties("AllowBypassKey") = False
    '        End If
    '    End If
    '
    '    Me.Visible = False
    '    Globals.Logging "Logon"
    '
    '    DoCmd.OpenForm "frmMainMenu"
    ''    DoCmd.Close acForm, Me.Name
        
        
    
    
    End Sub
    
    
    Private Sub Form_Unload(Cancel As Integer)
        Globals.Logging "Logoff"
    End Sub

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

Similar Threads

  1. Replies: 5
    Last Post: 01-12-2015, 03:44 PM
  2. Suppress "Error" message following "Cancel = True"
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 03-23-2014, 05:40 PM
  3. Replies: 2
    Last Post: 01-03-2014, 09:35 AM
  4. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  5. Replies: 17
    Last Post: 06-04-2012, 05:11 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