Query parameters for subform recordsource

Posted on 2000-02-16
Last Modified: 2012-05-04
I'm setting the recordsource of a datasheet subform. I want to use a predefined parameter query. How do I provide the parameter value to complete the query so the recordsource will run?
Question by:dwalex
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 10

Accepted Solution

brewdog earned 50 total points
ID: 2529762
How are you setting the recordsource? Where are you getting your parameter value? I would probably put a text box on the main form (even if you make it invisible) and have the query's criteria point to that text box. Then all you'd have to do is set the value of that text box in code and do a


Hope that helps . . .


Author Comment

ID: 2530214
The subform has no recordsource when it loads. I was trying to use

me.subform.recordsource = "Query Name"

but I while I can set the recordsource that way, I can't see how to programatically send the parameters for that predefined query to the subform.

The workaround is exactly as you suggested. It means the query is only useful from within the particular form, but it works.
LVL 10

Expert Comment

ID: 2531374
If you wouldn't lose too much speed by doing it, you could put the entire SQL string as the recordsource on the form's load event. Instead of

me.subform.recordsource = "Query Name"

You could do:

me.subform.recordsource = "Select * from YourTable Where YourField = " & YourParameter

You would probably slow down a little bit, because Access would have to run the query on the fly each time, losing the optimization it throws in for a saved query. But it's another option . . .


Author Comment

ID: 2531581
Dynamic SQL was an option, yes. But this particular update happens with every line item of every transaction in the system. The query contains a correlated subquery, and a lot of math, and hence is pretty complex. Performance of the dynamic SQL version would be iffy.

But in other cases, dynamic SQL is certainly a valid option. Thanks.
LVL 10

Expert Comment

ID: 2531588
no problem. didn't want to leave anything out.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linking Master Child Fields 2 28
Access Report formatting issue 5 27
Access vs Access runtime 6 19
Query Dilema in Access 2010 3 5
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question