S
Sarah at DaVita
How can I get my print button to just print the form I am looking at?
DoCmd.OpenReport stDocName, , _
WhereCondition:="[Vendor/Site]" = " & Me.vendor/site"
Sarah at DaVita said:Ok am trying that - makes good sense. Below is my code but it only prints a
blank report. The report has a field called vendor/site and the form also
contains this field - why whould it not print the data:?
Private Sub PrintformReport_Click()
On Error GoTo Err_PrintformReport_Click
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.
Tom Wickerath said:Hi Sarah,
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
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
Sarah at DaVita said:Ok am trying that - makes good sense. Below is my code but it only prints a
blank report. The report has a field called vendor/site and the form also
contains this field - why whould it not print the data:?
Private Sub PrintformReport_Click()
On Error GoTo Err_PrintformReport_Click
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.