Try this tutorial:
How to print only one page of a multipage report
http://www.access.qbuilt.com/html/reports.html#PrintOnePgOfRpt
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
stDocName = "VendorSiteAddresses_frm"
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
DoCmd.PrintOut
DoCmd.SelectObject acForm, MyForm.Name, False
I do not recommend that you attempt to print a form. Forms are for entering
and viewing data, but they're not intended for printing. For one thing, there
is no way of suppressing a form background from printing. Most forms have
some type of background.
Create a report with the same fields on it as your form. Then use the idea
that I show to open the report with just that one record. You can have a
command button on the form for opening the report. My ImageDemo database
provides an example of being able to print the current record displayed in a
form:
http://www.accessmvp.com/TWickerath/downloads/ImageDemo.zip
Dim stDocName As String
stDocName = "Vendor Sites and Addresses Report"
DoCmd.OpenReport stDocName, , _
WhereCondition:="[Vendor/Site]" = " & Me.vendor/site"
DoCmd.OpenReport
Exit_PrintformReport_Click:
Exit Sub
Err_PrintformReport_Click:
MsgBox Err.Description
Resume Exit_PrintformReport_Click
End Sub
Thanks for all your help on this.
Use the field on your form that serves as the primary key, since a primary
key uniquely identifies a given record. Is vendor/site your primary key
field? Also, your current usage indicates that vendor/site is a numeric
field. Is this correct?
> DoCmd.OpenReport stDocName, , _
> WhereCondition:="[Vendor/Site]" = " & Me.vendor/site"
You are using a named argument (WhereCondition), so you should not need the
second comma on the first line shown above. So, try this instead:
DoCmd.OpenReport stDocName, _
WhereCondition:="[pkField]" = " & Me.pkField"
where pkField is a numeric primary key, such as an autonumber. If you are
using a text-based primary key, then you need to include quotes, like this:
DoCmd.OpenReport stDocName, _
WhereCondition:="[pkField]" = '" & Me.pkField & "'"
If your primary key field includes spaces or special characters in it's
name, then you'll need to use square brackets as well, like this:
Numeric pk
DoCmd.OpenReport stDocName, _
WhereCondition:="[pkField]" = " & Me.[pkField]"
Text pk
DoCmd.OpenReport stDocName, _
WhereCondition:="[pkField]" = '" & Me.[pkField] & "'"
You will eliminate future headaches if you avoid the use of spaces and other
special characters, and reserved words, in anything that you assign a name to
within Access. So, for example, the vendor/site field would be better named
VendorSite. This way, Access will never interpret the forward slash as
division. The report named "Vendor Sites and Addresses Report" would be
better named "VendorSitesAndAddressesReport" (no spaces), or if you want to
use standard naming conventions "rptVendorSitesAndAddresses". Here are some
references on this topic:
Special characters that you must avoid when you work with Access databases
http://support.microsoft.com/?id=826763
Problem names and reserved words in Access
http://allenbrowne.com/AppIssueBadWord.html
I just realized that I forgot to mention that you should force a save of the
record, if you are using a bound form (a bound form is one that has a table
or query specified as the Record Source property). This way, your report will
always show the latest data changes. Using your procedure:
Private Sub PrintformReport_Click()
On Error GoTo Err_PrintformReport_Click
Dim stDocName As String
stDocName = "Vendor Sites and Addresses Report"
:
<rest of code here>
:
End Sub
Add the test for Me.Dirty to force a save of the record before opening the
report:
Private Sub PrintformReport_Click()
On Error GoTo Err_PrintformReport_Click
Dim stDocName As String
stDocName = "Vendor Sites and Addresses Report"
If Me.Dirty = True Then
Me.Dirty = False
End If
:
<rest of code here>
:
End Sub
This way, if you have made a change to the data in the form, without first
having saved it (ie. pencil symbol is shown in record selector, if you are
displaying the record selector), the report will include these changes since
you are forcing a save of the record first.