Results 1 to 7 of 7
  1. #1
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119

    Enter current logged in username into table

    Hi everyone,
    I have a form called "FRM_PRODUCT" which is used to enter records in my table "PRODUCT".
    And in that form there is a field called "addedby" which is a column of the table product.



    I also have a login form, where user select their username from a combo box and then enter their password into another text box, in order to get connected to the database.

    Now I want the field "addedby" to be automatically filled with the current username, anytime a new product is entered.

    Please can someone help me with that.
    Note that I am a beginner in access, so please provide detailed explanations.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I also have a login form, where user select their username from a combo box and then enter their password into another text box, in order to get connected to the database.
    Maybe you can store this value in a variable or in a textbox control. Then, from your FRM_PRODUCT, reference the variable or the textbox control.

  3. #3
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    Hi,
    happy to have you around.
    I have the logic in mind, however as i said earlier on i don't now much in Access/vb.
    so my issue is the implementation of it and the code that goes with it.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Do you have a form that stays open for the duration the application stays open? Maybe you have a Main Menu form or something. Place an unbound textbox in this form. Assign the 'login' value in this textbox control. There are a dozen ways to go about it. Without knowing how your app is set up, it is hard to offer an explanation how to implement it.

    For me, I combine the login and main menu form together, into one. If you have a series of forms that open at startup, You can use the fully qualified name of a form to pass a value to a control within it.

    Here is one example
    Forms!FormName.ControlName.Value = Me.ComboName.Value

    You just need to make sure both of the forms are open at the same time. So the code above might execute after a Docmd.OpenForm statement.

  5. #5
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    Hi ItsMe,
    sorry for not writting back to your proposed solution concerning my issue of auto selecting current logged in user. I had an issue with my laptop, anyway.

    I have tried to implement what you described above as solution to my issue, but still can't
    figure it out.
    So i attached a sample of the database that i am developping so that you have a close look at it.

    Attachment is here SampleDb.zip

    ================================================== ================================================

    A quick reminder above what i am looking to achieve
    ---------------------------------------------------
    Upon opening the attached database file you will notice that i have a table called "Tbl_Fertilizers"
    which has a column named as "AddedBy".
    Now what i am looking to achieve is that i want "The logged in username to be automatically inserted into
    the field "AddedBy" anytime a new record is created.

    I took the time to try and understand the above proposed solutions, but as i mentionned earlier Access is not my
    favorite Developpment tool so i did not understood much.

    Hope I am not over asking.
    Thx

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    If you place a textbox control on Frm_MainMenu and name it, "txtUserId", you can use the following code to assign the user ID to the new textbox control.

    Code:
    'Check value of password in tbl_Users to see if this
    'matches value chosen in combo box
    If Me.txtPassword.Value = DLookup("Password", "tbl_Users", _
    "[UserId]=" & Me.CboUsername.Value) Then
    
    'UserId = Me.CboUsername.Value
    
    'Close logon form and open Main Menu
    
    DoCmd.OpenForm "Frm_MainMenu"
    Forms!Frm_MainMenu.txtUserId.Value = Me.CboUsername.Value
    DoCmd.Close acForm, "Frm_LoginScreen", acSaveNo
    Else
    MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
    "Invalid Entry!"
    Me.txtPassword.SetFocus
    End If
    Then you can use code in the OnCurrent event of your Frm_AddFertilizer to assign the User ID to your Tbl_Fertilizers.
    Code:
    If Me.NewRecord = True Then
        Me![NameOfFieldForUserId] = Forms!Frm_MainMenu.txtUserId
    End If
    One thing that I noticed is that you are requesting to add the "Name" of the User. I suggest you store the Primary Key of the User ID. The name is in the Combo in the Me.CboUsername.Column(1)

  7. #7
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    Thx a bunch ItsMe.
    I used the code that you provided, and made some ajustements and everything is working as expected.
    Thank you once again.

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

Similar Threads

  1. How to creae username for people logged on to Access
    By Mubashir sabir in forum Security
    Replies: 3
    Last Post: 01-21-2016, 12:27 PM
  2. Replies: 1
    Last Post: 02-01-2015, 12:27 PM
  3. Enter current date and time into subform field
    By tonybrecko in forum Forms
    Replies: 8
    Last Post: 06-16-2013, 09:58 PM
  4. Replies: 5
    Last Post: 08-08-2012, 01:28 PM
  5. Access 2010 : Current logged in user
    By raghav_pegausis in forum Access
    Replies: 7
    Last Post: 10-24-2011, 02:52 PM

Tags for this Thread

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