Results 1 to 15 of 15
  1. #1
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145

    How can I add username when user makes an update?

    I have a simple multiuser login script seen below that works alright -

    Code:
    Private Sub Validate_Click()
    Username.SetFocus
    If Username = "Tom W" And Password = "tw123!" Then
    MsgBox "Access Granted - Welcome Tom", vbInformation, "Welcome"
    DoCmd.Close
    DoCmd.OpenForm "frm_Main_Menu"
    ElseIf Username = "Rich C" And Password = "rc123!" Then
    MsgBox "Access Granted - Welcome Rich", vbInformation, "Welcome"
    DoCmd.Close
    DoCmd.OpenForm "frm_Main_Menu"
    ElseIf Username = "Alex J" And Password = "Gal.2:20" Then
    MsgBox "Access Granted - Welcome Alex", vbInformation, "Welcome"
    DoCmd.Close
    DoCmd.OpenForm "frm_Main_Menu"
    ElseIf Username = "manager1" And Password = "manager1" Then
    MsgBox "Please Exercise Caution When Altering Back End", vbInformation, "Manager Area"
    DoCmd.Close
    DoCmd.OpenForm "frm_Main_Menu"
    Else
    MsgBox "Login Error - Please re-enter your information", vbInformation, "Login Error"
    End If
    End Sub
    but what I want is to have the username go in a field in the table whenever a user makes a change to a record in that table. Can I do this with this script? How would I do this? Thanks

  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
    I save the user ID to a textbox on a form that never closes (Main Menu) so it is always available for reference by any procedure.

    The trick is figuring out what event to put code in.

    Maybe in form BeforeUpdate event, something like:

    Me.fieldname = Forms!Main.tbxUser
    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
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Awesome idea! I will try it. Thanks

  4. #4
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Having trouble passing the username from the login form to the Main Menu so far I've tried putting =[Forms]![frm_login].[Username] in the default value of the text box (Username_main) on the main menu.

    Also tried putting Me.Username = Forms!frm_Main_Menu.Username_main in the BeforeUpdate event on the login form. What am I doing wrong? Thanks

  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,929
    Correction, what I really do now is bind MainMenu to Users table and open MainMenu filtered to user record. So from the login form:

    DoCmd.OpenForm "Main", , , "UserID=" & Me.UserID

    DefaultValue is only useful for new record on a bound form.
    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
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    I see. My script doesn't use a users table though, is there a way I can adapt it to use a users table? Thanks

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why would you set textbox on Login form to value from Main form? Isn't that backwards?

    Table not required - you have the validation hard coded. Not as flexible as table but functional. Populate a textbox on Login form with username. Close the Login form after opening Main form.
    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.

  8. #8
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Yeah I thought it was backwards, I must have misunderstood what you told me

  9. #9
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    I used the onLoad event for the Main Menu form, it all seems to work well. Now just have to figure out how to close the login form after the main menu form is loaded. Just DoCmd.Close closes the main menu form that just loaded

  10. #10
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Figured it out - DoCmd.Close acForm, "frm_login", acSaveYes. Thank you June!

  11. #11
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    So to recap for reference -

    I added

    DoCmd.OpenForm "frm_Main_Menu", , , "Username=" & Me.Username
    DoCmd.Close acForm, "frm_login", acSaveYes

    to my onclick event for the login button of my login form after the user puts in the correct username/password. Then added

    Private Sub Form_Load()
    Me.Username = Forms!frm_login.Username
    End Sub

    to the onLoad event of my main menu form. Works great. Thanks again June

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The acSaveYes is to save design changes, has nothing to do with saving data.

    Data is committed to table when form (or table) is closed or move to another record or run code (DoCmd.RunCommand acCmdSaveRecord).
    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.

  13. #13
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Yep I know

  14. #14
    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 using code to modify properties (Filter is one commonly treated with VBA), probably don't want to close the form and save the changes. I always use 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.

  15. #15
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Oh ok, thanks!

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

Similar Threads

  1. Replies: 14
    Last Post: 08-17-2015, 02:32 AM
  2. Replies: 6
    Last Post: 02-21-2013, 10:52 AM
  3. From that makes Multiple records
    By sgp667 in forum Forms
    Replies: 8
    Last Post: 10-12-2012, 06:51 PM
  4. Replies: 5
    Last Post: 08-08-2012, 01:28 PM
  5. Replies: 4
    Last Post: 11-10-2011, 03:41 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