Solved

Printing a subform in datasheet view

Posted on 2004-10-04
10
570 Views
Last Modified: 2011-08-18
Hi,
   I have a subform which is filtered on three combo boxes and I need to be able to print the filtered results in datasheet view, without printing the rest of the page. Hope someone can help me.
                   Thanks Rox
0
Comment
Question by:RoxanneMcCafferty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 39

Expert Comment

by:stevbe
ID: 12216224
make a report based on the same query as the subform and then use the filter property of the subform to build the WhereCondition argument of the OpenReport method.

On the main form add a button to print the report ...

Private Sub cmdPreview_Click()
    DoCmd.OpenReport ReportName:="MyReport"
                                 WhereCondtion:=Me.childForm.Form.Filter
End Sub

make sure that you replace childForm with the name of the subform control and not the name of the form that is embedded.

Steve
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 12216470
you can print the result of the query


Private Sub PrintQuery_Click()
Dim Sql As String, qd As QueryDef
Sql = "select * from TableName Where <conditions>"
Set qd = CurrentDb.CreateQueryDef("MyQuery", Sql)

DoCmd.OpenQuery "MyQuery", acViewPreview
DoCmd.PrintOut acPrintAll
DoCmd.Close acQuery, "Myquery"
DoCmd.DeleteObject acQuery, "Myquery"
End Sub
0
 

Author Comment

by:RoxanneMcCafferty
ID: 12244976
Hi sorry haven't been able to work on this for a while, trying to do the report thing recommended by steve but line;

          WhereCondtion:=Me.subPropertyView.Form.Filter
is getting a compile error at the := bit
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Accepted Solution

by:
stevbe earned 500 total points
ID: 12249292
sorry, I forgot the line continuation character ...

Private Sub cmdPreview_Click()
    DoCmd.OpenReport ReportName:="MyReport", _
                                 WhereCondtion:=Me.childForm.Form.Filter
End Sub

Steve
0
 

Author Comment

by:RoxanneMcCafferty
ID: 12255872
Thanks, but still nothing. I put in a couple of message boxes to see if event if firing and it's not. I definitely have the name right and did a new button even but no event happening. Below is code

Private Sub cmdPreview_Click()
MsgBox "Hello"
DoCmd.OpenReport ReportName:="propertyReport", _
WhereCondtion:=Me.subPropertyView.Form.Filter
MsgBox "Hello1"
End Sub
0
 

Author Comment

by:RoxanneMcCafferty
ID: 12255928

If I just have the following code it prints it, but no filter obviously, but shouldn't it just open it? Not print it straight away?

Private Sub cmdPreview_Click()
MsgBox "Hello"
DoCmd.OpenReport ReportName:="propertyReport", _
0
 

Author Comment

by:RoxanneMcCafferty
ID: 12255968
It's working now, thankyou so much, code below is same as 2nd last message I sent as far as I can see but now randomly working. Only thing I need to know now is how to preview it before it straight away prints.

Private Sub cmdPreview_Click()
MsgBox "Hello"
DoCmd.OpenReport ReportName:="propertyReport", _
                  WhereCondition:=Me.subPropertyView.Form.Filter
MsgBox "Hello1"
End Sub
0
 

Author Comment

by:RoxanneMcCafferty
ID: 12256282
Got it working now, thankyou
0
 
LVL 39

Expert Comment

by:stevbe
ID: 12257945
you should probably check to see if the filter is actually being used with the FilterOn property ...
the View argumant defines how the report is processed, the default is to print and that was what was happening so we can change it to preview ...

Private Sub cmdPreview_Click()
    If Me.subPropertyView.Form.FilterOn = True Then
        DoCmd.OpenReport ReportName:="propertyReport", _
                                     WhereCondition:=Me.subPropertyView.Form.Filter, _
                                     View:=acPreview
    Else
        DoCmd.OpenReport ReportName:="propertyReport", _
                                     View:=acPreview
    End If
End Sub

Steve
0
 

Author Comment

by:RoxanneMcCafferty
ID: 12263619
Good suggestion, will do that, thanks
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question