Solved

Query parameters for subform recordsource

Posted on 2000-02-16
5
1,204 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
no problem. didn't want to leave anything out.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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 views 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 Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now