Solved

Printing a subform in datasheet view

Posted on 2004-10-04
10
560 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
  • 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 119

Expert Comment

by:Rey Obrero
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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now