Results 1 to 6 of 6
  1. #1
    dgj32784 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    22

    Refer to a form control in a query based on whichever form is "active"

    I'm not sure if the title of this post makes any sense. Basically, I'm trying to figure out how to refer to a control on a form in a query criteria based on whichever form is "active." The scenario is I have many forms where I have a form control that retains a "master ID" and another control (combo box) that lists associcated "sub IDs." The value of the master ID control is passed to a query parameter that then selects all of the sub IDs that are related, which populates the list in the combo box on the form. But I don't want to create a query for every single form that needs this functionality simply because the form name is different.

    Is there a way to make the red outlined portion of the query criteria a "parameter" or "wildcard" such that the form name is popped into this query dependent on whichever form is "active?" Or in other words, is there a way to refer to the form in the query criteria as "Me?" Do I need to generate the SQL syntax using concatenation in VBA and pass that to the query?

    See attached JPG of query matrix.

    Any help would be appreciated.

    Thanks,
    David
    Attached Thumbnails Attached Thumbnails example.jpg  

  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,641
    I know you've cross-posted this, so I would waste too much time on it. You can't do directly what you're asking. You could copy values to a form that will always be open (like a main menu, or hidden criteria form) and have the query look there. You could create a function that used ActiveForm to determine the active form and return the value from it, and call the function in the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Short answer is no. However, VBA code can modify query using QueryDefs collection or any number of ways pass the 'master ID' value to the query.

    You have many forms that have these same two dependent comboboxes? Why are there many forms? Are they essentially identical?

    You don't need to create a query object for each combobox. You can build the SQL statement right in the combobox RowSource property. Or use VBA event to set the RowSource property of combobox.
    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.

  4. #4
    dgj32784 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    22
    Sorry for the cross-posting. I wasn't sure how varied the forum audiences were and thought I would increase my chances.

    Thanks for the reply and I think I understand what you have both suggested. I'll try the SQL route first and then the Function option.

    I know it seems strange to have these two "dependent" controls on a lot of forms, but the database is an in-the-woods survey database. There are many attributes associated with each survey related to these IDs but having all of this information on one (or few) forms is not practical. It would greatly disrupt the user workflow, make it hard to enter data on a form given we run the dbase on a touch screen TabletPC, and some of the information - while tied to these IDs - is best stored in seperate tables for easy data summary.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No problem; post back if you get stuck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Have you considered Form/Subforms arrangement with subforms on tab control?
    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: 5
    Last Post: 06-25-2012, 02:06 PM
  2. Replies: 15
    Last Post: 02-17-2012, 09:20 AM
  3. Update query from form "invalid use of null"
    By Lady_Jane in forum Programming
    Replies: 4
    Last Post: 08-16-2011, 01:37 PM
  4. Reffering to the "Active" form in a calculation.
    By Computer202 in forum Programming
    Replies: 1
    Last Post: 04-09-2010, 10:01 AM
  5. Replies: 1
    Last Post: 10-19-2009, 02:37 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