VBA Code for printing one page in a report

J

Janet Ocasio

I have a print command on my Form titled "Master Form" and
it prints my report titled "Master". I want to print one
page only from my report. I have the following code
entered but it still prints the whole report. What do I
need to change?

Dim stDocName As String
Dim stFilter as String
stDocName = "Master"
stFilter = Customer ID = Forms!Master Form!Customer ID"
DoCmd.OpenReport stDocName, acViewNormal, , strFilter

Any help would be appreciated.

Thanks,
Janet
 
A

Allan Thompson

Janet,

If you cut and pasted this directly from your code, I see a couple of
problems:
1) In the line stFilter = Customer ... ,
a) you need a double quote before Customer ID
b) since the column name has a space, I would suggest putting it in
brackets [Customer ID]. To alleviate hassles , try to avoid using spaces or
symbols (%,#, etc) in column names.
c) the value of Forms!Master Form!Customer ID gets lost inside the
quotes.
If Customer ID is a number, try this:
stFilter = "[Customer ID] = " & Forms!Master Form![Customer ID]
If Customer ID is a text field, try this:
stFilter = "[Customer ID] = '" & Forms!Master Form![Customer ID]
& "'"
(single quote after the = sign; last portion is double quote,
single quote, double quote
2) In the DoCmd line, you use strFilter; you used stFilter above

Hope this helps.
Allan
--
Allan Thompson
APT Associates/ FieldScope LLC
MS Office Automation / Measurement and Reporting Systems
www.fieldscope.com
860.242.4184
 

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

Similar Threads


Top