Solved

Query parameters for subform recordsource

Posted on 2000-02-16
5
1,219 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
[X]
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
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

688 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