Solved

Query parameters for subform recordsource

Posted on 2000-02-16
5
1,209 Views
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?
0
Comment
Question by:dwalex
  • 3
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
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

me.YourSubformName.Requery

Hope that helps . . .

brewdog
0
 
LVL 1

Author Comment

by:dwalex
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.
0
 
LVL 10

Expert Comment

by:brewdog
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 . . .

brewdog
0
 
LVL 1

Author Comment

by:dwalex
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.
0
 
LVL 10

Expert Comment

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

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

770 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