Page 1 of 1

Print Report With Current Record

PostPosted: Tue Feb 02, 2010 3:19 am
by macbeth
I have a form that shows 1 record at a time and I want to print the currently displayed record in a report from the form. Can this be done. Right now I have a button on the form that open a criteria form where I enter a parameter to print the currently displayed record. The criteria table is in the query with the main table. Clear as mud? Thank you!

Re: Print Report With Current Record

PostPosted: Mon May 17, 2010 12:38 pm
by OachKatz3L
I'm looking for the answer to this question too (Print current report of a form).
Does anyone have an example or "how to" to point to ?
Edit : SRB visibly uses tables or queries to build reports. Could someone confirm that if I'm looking for editing a current row of a form, I'll have to build a macro linking my row with a prepared report based on the queries and tables used by my form ?

Re: Print Report With Current Record

PostPosted: Thu May 20, 2010 10:09 am
by evwool
I've attached a db to show you how it works. It uses Villeroy's idea of a Filter Table to filter the report via the query on which the report is based. In one form, the macro only opens the report, in the other form, the macro puts a value into the Filter Table and then opens the report.

Ask if anything doesn't make sense.

[Resolved] Print Report With Current Record

PostPosted: Sat May 22, 2010 12:00 pm
by OachKatz3L
First macro is just simple & perfect :super:
Second is more complicated, but offers more ... still working on it
Thanks a lot.
(PS :Will the former author edit this post to [Resolved])

Re: Print Report With Current Record

PostPosted: Sat May 22, 2010 4:25 pm
by evwool
If you want any help making the second macro work, please say. It will help me, since my aim is to make my coding as transparent as possible so that it can be adapted easily.
That's why I haven't included any of the normal extras (error traps to make sure that the report isn't already open, for instance). It is possible that either the original author has already figured this out or he still needs a bit of help adapting the macro to his database.

Re: Print Report With Current Record

PostPosted: Mon Jul 27, 2015 8:45 am
by Andy-Jordaan
Hi Evwool,
This guide is Excellent and works well, However I am Struggling to get the Report to be in PDF format and not Writer

I have been following the guides of " Zizi64 " here ... 20&t=78257

and "sainttomn" with "JohnV" here ... highlight=
and not getting the document in PDF

Here is what I have so far, using your "EvsOrdersSimple Database

Code: Select all   Expand viewCollapse view

REM  *****  BASIC  *****

Sub Main

End Sub

Sub OpenReport(oEvent As Object)
Dim oReport As Object
Dim ReportName As String
'in this code, the query on which the report is based
'is  filtered when you use the Listbox and button in FrmOrders1
' to Filter your subform by customer
'all the code does is to open the report
ReportName = "RptCustomerStatement"
'the name of my report
oReport = ThisDatabaseDocument.ReportDocuments.GetByName(ReportName)
End Sub

Sub UpdateTable(oEvent As Object)
'EvsOrdersSimple - EW
'this code reads OrdID in the selected record in the table grid
'then changes the LOrdID field in TblLookup
'using Update SQL
'QryRptOrder is filtered by LOrdID
'and RptOrder is based on this query
Dim ParentForm As Object
Dim ReadField As Object
Dim ReadFieldName As String
Dim LookupValue As Integer
Dim WriteField As String
Dim WriteTable As String
Dim PrimaryKeyField As String
Dim PKFieldValue As Integer
Dim MySQL AS String
Dim oReport As Object
Dim ReportName As String
Dim oStatement AS Object

ReportName = "RptOrder"
ReadFieldName = "OrdID"
'the field in my subform
WriteField = "LOrdID"
'the field in my filter table
WriteTable = "TblLookup"
'the name of my filter table
PrimaryKeyField = "LookID"
PKFieldValue = 0
'The value of LookID in the first
'record of my lookup table

ParentForm = oEvent.Source.Model.Parent
'the button which started this macro
'is in OrderForm (see Form Navigator)
ReadField = ParentForm.Columns.GetByName(ReadFieldName)
'ie OrdID in OrderForm
LookupValue = ReadField.Value
'read the current value of the OrdID
oStatement = ParentForm.ActiveConnection.CreateStatement
'Make an Action SQL statement to change the value
'of LOrdID in TblLookup
'ParentForm is a Sub-SubForm but that doesn't matter
MySql = "UPDATE """ & WriteTable & """"
MySql = MySql & " SET """ & WriteField & """=" & LookupValue
MySql = MySql & " WHERE """ & PrimaryKeyField & """=" & PKFieldValue
'Make the Action SQL work
'Tidy up
oReport = ThisDatabaseDocument.ReportDocuments.GetByName(ReportName)
'open the report newly filtered by LOrdID


REM <a href=";t=78257" title=";t=78257">;t=78257</a>
'    Sub Expert_PDF     
    MyExportArea = "$A1:F200"
    PDF_URL = "File:///home/andy/Desktop/ReportName" 
'    print "After send to Desktop  step Two "
    Dim args2(1) as new
    Dim Arg(0) as new
    Arg(0).Name = "Selection"
    Arg(0).Value = oRange
    args2(0).Name = "FilterName"
    args2(0).Value = "calc_pdf_Export"
    args2(1).Name = "FilterData"
    args2(1).Value = Arg()


'   End Sub


End Sub

Any pointers would be appreciated