I want to preview, not print, how do I?

G

Guest

I have posted this question in the query group, but I'm not sure if anyone
will see it, so I thought I would post it here as well.

I recieved a solution to a query problem ..... wanting to run a query from a
combo box selection for the parameters.
The solution I recieved is as follows-

"Make a new unbound form or use an existing form.
Add a combo box that will show the CodeID field.
Make sure the Combo Box Bound Column is the
same DataType as the CodeID field.
Add a command button.
Code the button's Click event:
DoCmd.OpenQuery "QueryName"
DoCmd.Close acForm, Me.Name
Name this form "ParamForm"

Code the Query CodeID field's criteria line
forms!ParamForm!ComboBoxName

Open the form.
Find the CodeID in the combo box.
Click the command button.

The query will display just those records selected.
The Form will close."

I use this code to actually open a report, however the report goes to print.
How do I get it to go to preview?
 
F

fredg

I have posted this question in the query group, but I'm not sure if anyone
will see it, so I thought I would post it here as well.

I recieved a solution to a query problem ..... wanting to run a query from a
combo box selection for the parameters.
The solution I recieved is as follows-

"Make a new unbound form or use an existing form.
Add a combo box that will show the CodeID field.
Make sure the Combo Box Bound Column is the
same DataType as the CodeID field.
Add a command button.
Code the button's Click event:
DoCmd.OpenQuery "QueryName"
DoCmd.Close acForm, Me.Name
Name this form "ParamForm"

Code the Query CodeID field's criteria line
forms!ParamForm!ComboBoxName

Open the form.
Find the CodeID in the combo box.
Click the command button.

The query will display just those records selected.
The Form will close."

I use this code to actually open a report, however the report goes to print.
How do I get it to go to preview?

It always pays to state the full question when posting, as the reply
will then be more relevant to what you are doing.
I specifically started my reply with...
Is the query the end result or is the query to be used as the record
source for a report?
The following is if the query is the end result.
etc. etc.

The code above does not open a report.
And it's not supposed to.

If you wish to run a report using the combo box for the parameter,
make the following changes.

Create an unbound form.
Add a combo box.
Set the Row Source of the combo box to include the
CodeID field.
Name the Combo Box 'FindCode'.
Set it's Bound column to 1.
Set the Column Width property to 1"

Add a Command Button to the form.
Code the button's click event:

Me.Visible = False

Name this form 'ParamForm'.

In the Report's Record Source (the query) [CodeID] field criteria line
write:
forms!ParamForm!FindCode

Next, code the report's Open event:
DoCmd.OpenForm "ParamForm", , , , , acDialog

Code the report's Close event:
DoCmd.Close acForm, "ParamForm"

When ready to run the report, open the report in PREVIEW.
The form will open and wait for the selection of the Code.
Click the command button and then report will run.
When the report closes, it will close the form.

How are you opening the report?
Using code in an event? If so:

DoCmd.OpenReport "ReportName", acViewPreview

From the main database window?
Right-click on the report name and select Print Preview.
 

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