Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    RowSource or DLookUp for changing a control source in txtbox?

    HI all,
    I have a bound form to where i am trying to display the records only that are related to the combo selection.
    I cant figure out how to make this work. I want to open form, with PrimaryRole Records related to whatever is in CboPrimaryIndustry


    and if i change the CboPrimaryIndustry i want it to change to related records? I can do it with a combo box but i cant do it with a text box?

    Attached is a mach up db i put together for this.
    Thanks

    Dave
    Test.zip

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This:

    Me.TxtPrimaryRole.ControlSource = "Select * From PrimaryRoleTbl Where PrimaryIndustryID=" & Me.CboPrimaryIndustry

    would need to be more like:

    Me.TxtPrimaryRole = DLookup("PrimaryRole", "PrimaryRoleTbl", "PrimaryIndustryID=" & Me.CboPrimaryIndustry)

    but it doesn't make sense to be a textbox since there could be multiple records that match the criteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi, What i want to do is just display the records from the table "PrimaryRoleTbl" that are related to the Combo "CboPrimaryIndustry"
    So if Construction is Listed in CBO, I would only show the records related to ConstructionID in the PrimaryRoleTbl...
    If I change the combo to a different industry, then it would change the records that relate to that industry...

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You'll need a combo or listbox to list multiple records. If you want to see them like:

    Engineer, General Contractor, ...

    you'll need to use a recordset to loop the values and build that string. Or you could use:

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

    which implements that technique.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I dont want them to be side by side, i want to show all records that relate to the combo ID in a continous form.
    So if
    Construction Industry Selected,
    Then Continuous form would show the all records relating to that selection such as:

    Architect
    Engineer
    General Contractor
    And so on...

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, you could do this:

    Me.RecordSource = "Select * From PrimaryRoleTbl Where PrimaryIndustryID=" & Me.CboPrimaryIndustry

    or set the Filter:

    Me.Filter = "PrimaryIndustryID=" & Me.CboPrimaryIndustry
    Me.FilterOn = True
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    The attached db show two possible ways to do this

    On one form the forms Record Source is changed dependent on the combo selection

    On the other form a filter is applied dependent on the combo selection
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thank you,
    That worked perfect!
    Again, Thank you...

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help! Sorry about misunderstanding the goal.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by d9pierce1 View Post
    Thank you,
    That worked perfect!
    Again, Thank you...
    The attached db shows a third way:
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I have only one issue with all the methods! It doesnt put the PrimaryIndustryID in the PrimaryRoleTbl when adding a new record? Is there a way to fix that so i can add new records?
    Thanks

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    If you add a new record to PrimaryIndustryTbl, how would Access know which PrimaryRole to apply? And would an existing Role apply, or would/could a new Role be required?

  13. #13
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    In the attached db the PrimaryIndustryID is added to the new record provided there is already a selection made in the header combo

    EDIT:
    Should have said that the suggested solution can be found using the third version of the form
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  14. #14
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    If you add to PrimaryIndustryTbl it will require you to add new records... Records would be blank or null till you inserted new records to that Industry. But the methods above will allow me to add a new record but will not put the ID in for the PrimaryIndustryID into the PrimaryRoleTbl? In the methosd above, Method 3 works with the exception to not being able to save the PrimaryIndustryID as is unbound, the other methods change first record to a different PrimaryIndustryID which is bazzar to me? Basically if i add a new record to this i want it to be saved with the PrimaryIndustryID from the current Combo in the form.

  15. #15
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    That works super fine! Thank you so much...I will get this one day, i promise....

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

Similar Threads

  1. RowSource and Control Source defined
    By Lou_Reed in forum Access
    Replies: 5
    Last Post: 05-30-2017, 01:55 PM
  2. Replies: 12
    Last Post: 12-10-2013, 08:57 PM
  3. DLookup in Control Source
    By bgephart in forum Forms
    Replies: 2
    Last Post: 08-28-2012, 02:06 PM
  4. DLookup() for Text Box Control Source
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 02-06-2012, 02:21 PM
  5. Dlookup as Control Source
    By alsoto in forum Forms
    Replies: 1
    Last Post: 08-28-2011, 07:05 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