Results 1 to 6 of 6
  1. #1
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100

    how to query specific fields based on other table field requirements?

    Hi all.

    I have a table named 'Query_Req' that contains the fields that are required for that specific type of customer. I also have a table with data that I would like to query (up to 10k records) but only return the fields that customer requires.

    Would it be possible to have my query automatically return the required fields from the 'Query_Req'? This table will be updated on an annual basis and required fields might be added/removed.



    Ex. For ex. Customer_B only needs four fields, so a query would only return those.

    I understand I would need two queries to achieve this and that's okay. I just don't know if this is possible or how to start.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    I would build the query statement by reading through the recordset of your customer fields?

    If you have them horizontally instead of vertically, then read through each field in the record.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Please have a look at the attached sample, I think it should give you what you need .

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    Thanks Gicu - how did you get the query to change to the required fields and filter? I am trying to understand but lost there a bit.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Have a look at the AfterUodate event of the customer type combo box. I use a public VBA function to build the comma- separated string of field names for the selected type then use that to update the SQL property of the query (using the DAO.QueryDef.SQL property).
    Cheers,

  6. #6
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    thank you - I see that now.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2021, 06:45 AM
  2. Replies: 10
    Last Post: 11-09-2017, 10:10 AM
  3. Replies: 34
    Last Post: 08-11-2016, 08:26 AM
  4. Replies: 1
    Last Post: 02-27-2015, 05:03 PM
  5. Replies: 1
    Last Post: 11-10-2009, 03:20 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