Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / April 2008

Tip: Looking for answers? Try searching our database.

Printing a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sarah at DaVita - 26 Apr 2008 01:57 GMT
How can I get my print button to just print the form I am looking at?
Tom Wickerath - 26 Apr 2008 02:04 GMT
Hi Sarah,

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
__________________________________________

> How can I get my print button to just print the form I am looking at?
Sarah at DaVita - 28 Apr 2008 17:53 GMT
Don't know how to change the code - the instructions are for a report and I
am working with a form. I can easily add the dim statement but do not know
where to put the where clause.   My code is below.
   Dim stDocName As String
   Dim MyForm As Form

   stDocName = "VendorSiteAddresses_frm"
   Set MyForm = Screen.ActiveForm
   DoCmd.SelectObject acForm, stDocName, True
   DoCmd.PrintOut
   DoCmd.SelectObject acForm, MyForm.Name, False

> Hi Sarah,
>
[quoted text clipped - 10 lines]
>
> > How can I get my print button to just print the form I am looking at?
Tom Wickerath - 28 Apr 2008 18:03 GMT
Hi Sarah,

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

Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

> Don't know how to change the code - the instructions are for a report and I
> am working with a form. I can easily add the dim statement but do not know
[quoted text clipped - 7 lines]
>     DoCmd.PrintOut
>     DoCmd.SelectObject acForm, MyForm.Name, False
Sarah at DaVita - 28 Apr 2008 21:08 GMT
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.

> Hi Sarah,
>
[quoted text clipped - 28 lines]
> >     DoCmd.PrintOut
> >     DoCmd.SelectObject acForm, MyForm.Name, False
Tom Wickerath - 29 Apr 2008 00:28 GMT
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
__________________________________________

> 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
[quoted text clipped - 18 lines]
>
> Thanks for all your help on this.
Sarah at DaVita - 29 Apr 2008 00:36 GMT
Thank you!!!  I did finally figure out that I needed to make my vendor/site a
literal.  All you experts who help us out are great!!

> Hi Sarah,
>
[quoted text clipped - 72 lines]
> >
> > Thanks for all your help on this.
Tom Wickerath - 29 Apr 2008 05:25 GMT
Glad to hear that you got it working!
I still encourage you to avoid the use of special characters (spaces,
forward slashes, etc.), along with any reserved words, in anything that you
assign a name to within Access (fields, tables, queries, forms, reports,
macros, modules, along with controls on forms and reports).

Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

> Thank you!!!  I did finally figure out that I needed to make my vendor/site a
> literal.  All you experts who help us out are great!!
Tom Wickerath - 30 Apr 2008 04:49 GMT
Hi Sarah,

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.

Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.