Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142

    Populate List box from TextBox

    Hi
    I have two tables :
    1. Employee : EmployeeID, EmployeeName ..
    2. Project: ProjectID, EmployeeID, ProjectName, ElementName , WBS

    TextBox (EmployeeID) : displays employee ID (Populates from another list Box selection)
    List Box (ListProject) : displays ProjectName, ElementName, WBS

    Once the EmployeeID populated from another list Box
    I want the ListProject should populate the list of projects associated with that employee ID.

    Could you please help me with this.
    I tried placing this query in the after update function in the text box:
    Private Sub EmployeeID_AfterUpdate()
    Dim SQL As String
    SQL = "Select ElementName,ProjectName,WBS From[Project] where [EmployeeID] = " & Me![EmployeeID].Value
    Me!
    [ListProject].RowSource = SQL
    Me!
    [ListProject].Requery
    End Sub

    And added the rowsource of the List box as this :
    to the employee ID: In criteria:

    [Forms]![formname]![EmployeeID]




    But the values are not populating.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    you dont need to write code for queries. just : docmd.openquery "qsMyQuery"

    the query would use the SQL based on the item on the form
    Select ElementName,ProjectName,WBS From[Project] where [EmployeeID] = forms!MyForm!EmployeeID

    are you trying to assign the project to the person on the form?
    or
    are you trying to view all persons assigned to the project in the listBox?

  3. #3
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I am trying to view the project assigned to the person in the list box.


    Quote Originally Posted by ranman256 View Post
    you dont need to write code for queries. just : docmd.openquery "qsMyQuery"

    the query would use the SQL based on the item on the form
    Select ElementName,ProjectName,WBS From[Project] where [EmployeeID] = forms!MyForm!EmployeeID

    are you trying to assign the project to the person on the form?
    or
    are you trying to view all persons assigned to the project in the listBox?

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Sounds very confusing. You have a listbox selection that populates a text box that is used as criteria to populate yet another listbox?
    We could grasp this a bit better if you post your DB.

  5. #5
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    sorry for not being clear.
    I would like to populate the listbox from the data in the text box .


    Quote Originally Posted by davegri View Post
    Sounds very confusing. You have a listbox selection that populates a text box that is used as criteria to populate yet another listbox?
    We could grasp this a bit better if you post your DB.

  6. #6
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142

    Populate List box from text box

    I have attached the sample db.
    My goal is to display the already assigned projects, when the employee is selected from the sub form.

    And whenever a new project is assigned to the employee, the list should update.
    Could you please help me with this.
    Attached Files Attached Files

  7. #7
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I have attached the Db for your reference.
    Quote Originally Posted by davegri View Post
    Sounds very confusing. You have a listbox selection that populates a text box that is used as criteria to populate yet another listbox?
    We could grasp this a bit better if you post your DB.

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Try this. Revised the form completely. The employee listbox did not need to be in a subform.
    The form itself needs no recordsource.
    Added 'ADD' and 'REMOVE' buttons between the project listboxes and added code to
    update the junction table as projects are added or removed from the listboxes.
    Added a couple more employee names for testing.

  9. #9
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Thank you so much ! I will go through the solution!
    Thanks again!!
    Quote Originally Posted by davegri View Post
    Try this. Revised the form completely. The employee listbox did not need to be in a subform.
    The form itself needs no recordsource.
    Added 'ADD' and 'REMOVE' buttons between the project listboxes and added code to
    update the junction table as projects are added or removed from the listboxes.
    Added a couple more employee names for testing.

  10. #10
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I have one more question. How do I add a search the employee List using the text box?
    I added a text box
    Apply filter in macro:
    [Employee].[FullName] Like "*" & [Forms]![EmployeeProjectForm]![lstEmployee]![txtSearch] & "*"
    but I am getting an error. What am I missing out?



    Quote Originally Posted by davegri View Post
    Try this. Revised the form completely. The employee listbox did not need to be in a subform.
    The form itself needs no recordsource.
    Added 'ADD' and 'REMOVE' buttons between the project listboxes and added code to
    update the junction table as projects are added or removed from the listboxes.
    Added a couple more employee names for testing.

  11. #11
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Can't use a filter as form is unbound.
    Add a textbox named txtSearch and set its AfterUpdate event like this:
    This will add criteria to the listbox rowsource.
    Code:
    Private Sub txtSearch_AfterUpdate()
        Dim sRowsource As String
        sRowsource = "SELECT Employee.[Employee_PK], [Employee].[Fullname] FROM Employee WHERE Employee.Fullname LIKE """ & "*" & txtSearch & "*" & """"
        lstEmployee.RowSource = sRowsource
        lstEmployee.Requery
    End Sub

  12. #12
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Thank you so much! It worked!!
    Quote Originally Posted by davegri View Post
    Can't use a filter as form is unbound.
    Add a textbox named txtSearch and set its AfterUpdate event like this:
    This will add criteria to the listbox rowsource.
    Code:
    Private Sub txtSearch_AfterUpdate()
        Dim sRowsource As String
        sRowsource = "SELECT Employee.[Employee_PK], [Employee].[Fullname] FROM Employee WHERE Employee.Fullname LIKE """ & "*" & txtSearch & "*" & """"
        lstEmployee.RowSource = sRowsource
        lstEmployee.Requery
    End Sub

  13. #13
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Hi I have a problem with the changes I am trying to implement.<br>
    I am attaching the Db for your reference.<br>
    What I am trying to implement is:
    1. To have the element name along with the project details in the "Lst assigned and Lst available " List boxes.
    2. Next, once the employee is selected : Out of the projects in the "LstAvailable box" , the User can also filter it through the "Element " Combo box placed on its top.

    Could you please help me with this.
    I tried querying. But its not displaying any results.
    Quote Originally Posted by davegri View Post
    Can't use a filter as form is unbound.
    Add a textbox named txtSearch and set its AfterUpdate event like this:
    This will add criteria to the listbox rowsource.
    Code:
    Private Sub txtSearch_AfterUpdate()
        Dim sRowsource As String
        sRowsource = "SELECT Employee.[Employee_PK], [Employee].[Fullname] FROM Employee WHERE Employee.Fullname LIKE """ & "*" & txtSearch & "*" & """"
        lstEmployee.RowSource = sRowsource
        lstEmployee.Requery
    End Sub
    Attached Files Attached Files

  14. #14
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    1. To have the element name along with the project details in the "Lst assigned and Lst available " List boxes.
    This functionality is already present. The reason the element in the listbox is blank is because the element field in the table is blank.
    2. Next, once the employee is selected : Out of the projects in the "LstAvailable box" , the User can also filter it through the "Element " Combo box placed on its top.
    Added the combobox and the criteria for the lstAvailable listbox.
    This might be a bit confusing, because the right listbox is not altered by the contents of the combobox. It acts like it did before the combobox was added.
    If we filter the right listbox the same as the left, that would mean that assigned projects might not show when they were actually assigned.

  15. #15
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Yes! That makes sense!!
    It doesn't filter according to the combo box value.
    Thank you so much for your prompt replies every time !!

    Quote Originally Posted by davegri View Post
    This functionality is already present. The reason the element in the listbox is blank is because the element field in the table is blank.

    Added the combobox and the criteria for the lstAvailable listbox.
    This might be a bit confusing, because the right listbox is not altered by the contents of the combobox. It acts like it did before the combobox was added.
    If we filter the right listbox the same as the left, that would mean that assigned projects might not show when they were actually assigned.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-01-2018, 03:10 AM
  2. Replies: 5
    Last Post: 09-12-2017, 12:41 AM
  3. Replies: 3
    Last Post: 06-24-2017, 07:37 AM
  4. Auto Populate TextBox
    By Shido151 in forum Access
    Replies: 3
    Last Post: 04-23-2013, 10:41 AM
  5. Replies: 1
    Last Post: 11-23-2012, 10:26 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