Mel H
Mel H

Reputation: 21

MS Access Parameter Query inside Subform Won't Print

Here's what I've done:

I created a Parameter Query in which one of the crtiterias is Between [Start Date] and [End Date]. I then put that Parameter Query along with other bound fields and created a subform. So far, no problems and it works great.

But I'm having issues when it comes to printing or trying to convert the form into a PDF. As soon as I ask it to print, for example, the pop-ups from the parameter query will pop up asking me the dates again and even after I enter them in (again), it keeps asking me multiple times and cancels the print job.

How do I keep the query from essentially running when I'm trying to print what's on the screen? The same thing happens if I'm trying to create a PDF.

Upvotes: 2

Views: 665

Answers (1)

BIBD
BIBD

Reputation: 15414

In my not so humble opinion, parameters are handled badly in MS Access.

I think having to enter the values in the query whenever it is run (unless it is a one off experimental query) is just wrong headed. It would be so much easier to automate reports like that if you could just pass the parameters.

Typically, I create a report without the parameters in the where clause of the query, and then pass in your own where condition which gets added on Remou's answer here

You could also alter the query in the report before you call it, but that's pretty hackey.

-- Edit --

I see the confusion. I interpreted what you were doing as a report (not a form).

What's likely happening is you that when it tries to render/format the print job, it's having to make multiple calls to form's record source. And that why it keeps asking you for that data.

From what I understand in your question, you have a query that looks like this:

select foo 
from bar 
where 
    yaddah_date between [Start Date] and [End Date]

And then you've used that query as the record source for a form that you are trying to latter print as a PDF. First of all you should probably create a report that is an analogue of the form. And then open the report for printing with a filter on it:

DoCmd.OpenReport "myReport", , , , _
                    "yaddah_date between " & txtStartDate & _
                        " and " & txtEndDate

(the last part is basically the filter/where clause that report will apply to the results of the query that's generating its data).

If you MUST print the form, you can do something similar

DoCmd.OpenForm "foo", acNormal, , _
                "yaddah_date between " & txtStartDate & _
                    " and " & txtEndDate

Or you can set the filter property of the form/subform.

Upvotes: 1

Related Questions