Solved

Printing a subform in datasheet view

Posted on 2004-10-04
10
563 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 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

786 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