Results 1 to 8 of 8
  1. #1
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253

    Form Text box

    I have frmEmployees that has a text box (txtAreaSelect). I am trying to pull the AreaNickname field records from tblAreas whose EmpID matches the hidden EmpID textbox on the frmEmployees.



    I am having a brainfart. I am having trouble getting this to happen. There could be multiple AreaNicknames for each EmpID. I want all the nicknames to populate the txtAreaSelect textbox as a list.

    Thank you for any help.

    Walker

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    if you want a list, use a listbox rather than a textbox. Other cosider using Allen Browne's concatrelated function

    http://allenbrowne.com/func-concat.html

  3. #3
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I tried a listbox also. I couldn't get that to work properly. I was trying to just get the query to work on a textbox. Right now I am getting ALL the records in the AreaNicknames field.

    Code:
    SELECT tblAreas.AreaNickname, tblAreas.EmpID FROM tblAreas INNER JOIN tblEmployees ON tblAreas.EmpID = tblEmployees.EmpID WHERE (((tblAreas.EmpID)=[tblEmployees]![EmpID]));

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    that sql will produce for all employees - in the listbox rowsource think you need something like

    SELECT tblAreas.AreaNickname, tblAreas.EmpID FROM tblAreas WHERE tblAreas.EmpID =[txtEmpID];

    where txtEmployee is the name of the control on your form that is bound to EmpID

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by NightWalker View Post

    ...I was trying to just get the query to work on a textbox...
    Sorry, but you cannot use a SQL Statement/Query as the Control Source for a Textbox...period!

    If there was one AreaNicknames per EmpID, you could use the DLookup() function to populate the Tetxtbox, but to list multiple AreaNicknames for a given EmpID you'll have to use either a Listbox, a Combobox or have the nicknames displayed in a Subform.

    Linq ;0)>

  6. #6
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I switched the textbox to a listbox but I am still having trouble getting the correct output to the listbox. I had DLookup() properly for the textbox until they added multiple areas for a few employees. Thank you all for your input and knowledge.

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    now you have a listbox, put the code in post #4. Noticed a small typo

    where txtEmpID is the name of the control on your form that is bound to EmpID

  8. #8
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Thanks Ajax That worked perfectly and I see where I was going wrong. I appreciate everyones help.

    I did an after update event on the employees last name and put a requery in there to get the listbox to update to areas for new employee.

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

Similar Threads

  1. Replies: 2
    Last Post: 01-10-2016, 06:47 PM
  2. Replies: 7
    Last Post: 06-05-2015, 11:13 AM
  3. Replies: 6
    Last Post: 03-05-2015, 01:42 PM
  4. Replies: 1
    Last Post: 03-27-2014, 06:42 AM
  5. Replies: 2
    Last Post: 03-01-2012, 12:21 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