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
Solved

Printing a subform in datasheet view

Posted on 2004-10-04
10
564 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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…
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.
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

790 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