Results 1 to 9 of 9
  1. #1
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283

    Assigning combo box value based on Environ("UserName")

    Hello,



    What I want to do is when a person opens the form(frmRep) it will autopopulate my combobox(cmboRepresentative) with the first name of the person using it. I have made a table(tbl_Users) that has the persons Username and first name and other information on it. The first name field is called "First_Name". The row source of the of the combo box already has a query with all the reps names. I am trying to figure out the best way when the user logs on I can link the Environ("UserName") property to my table and assign the combo box with the first name.

    Thank you

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    the combo box must have 2 columns, the UserID, and UserName
    set the combo box bound col = UserID
    set the #columns = 2
    set the col Widths = 0;2 (this hides the userid)

    when you assign the userid, cboBox = Environ("UserName")
    the combo box STORES the userid
    but SHOWS the name.

  3. #3
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    I can't set the combobox Control Source to UserID this form is bound to another table. This is a different table that has the UserID and UserName

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    yes, the tUser table FEEDS the field in your data table. (hence the combo box)

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    What field is the combobox bound to? Are you saving UserID as foreign key into this field? And if not, why not?

    Set Value of combobox to the UserID with a DLookup().

    Me.cmboRepresentative = DLookup("UserID", "tbl_Users", "UserName='" & Environ("USERNAME") & "'")
    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
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    The combo box isn't bound. SO keep the row source blank? I tried that Dlookup function and it doesn't return anything

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    What is purpose of combobox? If not data entry, selecting criteria for filtering records?

    I also tried Ranman's suggestion. Doesn't work either if combobox is unbound and has alias lookup.

    Code actually gets more complicated. After setting Value of combobox, 'go to' the relevant row:

    Forms!frmRep!cmboRepresentative.Selected(1) = True

    Also works with listbox.

    So what are your combobox settings:

    ControlSource: you already said is unbound
    BoundColumn: ?
    RowSource: ?
    ColumnCount: ?
    ColumnWidths: ?
    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
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    I just have my row source set to a query which is made from tblUsers which has the First_Name field and username field. And I just put my column count to 1.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    Then instead of UserID in the DLookup, use First_Name.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-12-2016, 12:58 PM
  2. Replies: 8
    Last Post: 08-13-2015, 11:08 AM
  3. Replies: 0
    Last Post: 03-13-2013, 08:00 AM
  4. Replies: 1
    Last Post: 02-17-2013, 04:46 PM
  5. Environ("username") ---> #Name? Error
    By KiEESH in forum Forms
    Replies: 2
    Last Post: 02-15-2013, 07:23 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