Solved

Query parameters for subform recordsource

Posted on 2000-02-16
5
1,210 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

808 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