Solved

Printing a subform in datasheet view

Posted on 2004-10-04
10
566 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…

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