Printing query from form

P

Pendragon

Access03/WinXP

I have a client with many nontechnical (no Access experience) personnel, so
I am having to customize some of my features so that a person nevers has to
get to the database window to open and/or print a query or query results.

I have a form whose subform is a datasheet of the query results. On the
parent form I've set up a button to save and open the results in an Excel
file. I would also like to have a button on the parent form that will print
the query results.

I've used ** DoCmd.OpenQuery strQryName, acPreview ** which is good insofar
as from this view, the user recognizes the preview screen and can print the
results. The issue is that this opens the query in the background, so when
the user closes the preview window, the display goes to the open query. I
would like instead to have the open query closed and the user brought back to
my form.

OR.....with my parent form open and the query results displayed in the
subform, how do I go about printing the query results directly from the form
with no intermediate steps?

Thanks for the assistance.
 
P

Pendragon

Okay, I got a little creative with my searches in the groups and found a
solution, though I would appreciate any feedback to a more proper or
appropriate, if you will, solution.

strName as String
strName = me.lblQryName.caption

DoCmd.OpenQuery strName
DoCmd.RunCommand acCmdWindowHide
DoCmd.SelectObject acQuery, strName
DoCmd.PrintOut acSelection
DoCmd.Close acQuery, strName

I had to put a docmd.maximize in the form's OnActivate property also. The
unfortunate side effect is that while the print is successful, the windows
flash and bounce around a bit. To the untechnical people, this might make
them nervous, but in the long run I think it's good for them. ;-)
 
P

Pendragon

Yes, I've gathered that from reading other threads. Here's my issue:

The report would be based on a combo box selection on the form; thus, the
report's record source would be change depending on the user's selection, and
depending on the query selected, the fields for the report would vary in
number and in name.

Yes, I want only one report for whatever is selected in the combo box,
because otherwise there would simply be too many reports to configure and
continually modify, and really isn't practical going forward as new
customized queries are written/developed.

Is there a way to set up a generic style report to accommodate varying
fields and names based on the record source?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top