LO Base failure using filter table and macro to print a row of data

Dear fellow Base enthusiasts/,

weekend again and I have studied the sample files by Ratslinger (Thank you Ratslinger!) from this post: Base: Print Button

It gave me lots of inspiration. I try to make something similar (see the attached file).

  1. I made a filter table (tblSPL_Filter, which has only two fields: a primary ID, field type Boolean and an Integer field) to hold the number to a row of data (SPL document) to be printed.
  2. I made a push button in the frm_SPL form under subform PrintForm (Data content is tblSPL_Filter), the button is attached to a macro:

Option Explicit

Sub OpenReport
Dim oController As Object
Dim oReportDoc As Object
oController = ThisDatabaseDocument.currentController
if not oController.isconnected then oController.connect
oReportDoc = Thisdatabasedocument.reportdocuments.getbyname(“rptSPL”).open
End Sub

Sub PrintCurrent
Dim oForm As Object
Dim oColumn As Object
Dim iField As Integer
Dim oSubForm As Object
Dim oController As Object
Dim oReportDoc As Object
oForm = ThisComponent.Drawpage.Forms.getByName(“MainForm”)
iField = oForm.getByName(“fmtSPL_ID”).Text
if oForm.isNew() Then
MsgBox “New Record - Cannot Print”
Exit Sub
End If
oSubForm = oForm.getByName(“PrintForm”)
oColumn = oSubForm.Columns.getByName(“Sel_SPL”)
oColumn.updateInt(iField)
oSubForm.updateRow()
oController = ThisDatabaseDocument.currentController
if not oController.isconnected then oController.connect
oReportDoc = Thisdatabasedocument.reportdocuments.getbyname(“rptSPL”).open
End Sub

which should displays the report (rptSPL).

Unfortunately I failed to make it work. I noticed that the filter table tblSPL_Filter won’t be updated when I click the push button (Print SPL test) on the frm_SPL form.

If I manually change the value of the field Sel_SPL in the filter table, then it works, i. e., when I clicked the push button the corresponding SPL document is displayed correctly.

One month ago I made something similar successful: LO Base how to print just one row data (in report) at a time

Not this time, I don’t know where I made mistakes. I really want to understand the whole mechanism of using filter table and macro to achive such function. Any insight and help will be very much appreciated. :pray:

And are there any other easier solutions to print a specific row of data (corresponding to a specific ID)? Anyone can introduce me any resources (ebooks, videos) on this topic (using filter table) for further learning? Thanks!!! :pray:

(LibreOffice 7.1,5.2, Mac OS X 10.16, HSQLDB)

Basetran_Repair.odb (51.5 KB)

Hello,

The solution is quite simple - use the correct macro :slight_smile:

The button is currently attached to the OpenReport sub and this does nothing but open the report. Just change to the PrintCurrent sub and all works OK.

Dear Ratslinger, thank you so much!!! You are absolutely right! That did the trick. Ach! My agony! Over-worked mind turned to such clumsy and awkward state. Thank you again!!! :pray: :pray: :pray: You’re a treasure here in this community. :+1: :+1: :+1:

@pauly

You are quite welcome. However, please no more :pray: - that is for those above much more powerful than anything else I know.
.
Thank You is always welcome.

1 Like

If your print button would belong to some other form (an extra dummy form will do), you could save a lot of because clicking the button will take away the focus from the criteria form and save any modified values automatically. You macro would simply open the report.
Simple Basic code to open any form or any report embedded in any database document. Just save in “My Macros” and add the name of the form or report to the “additional info” property of the calling button (this is what “additional info” was made for).

Sub Open_Report_Button(e)
REM specify the hierarical name in the button's "Additional info" field
	sName = e.Source.Model.Tag
	OpenEmbedded(ThisDatabaseDocument, sName, bReport:=True)
End Sub

Sub Open_Form_Button(e)
REM specify the hierarical name in the button's "Additional info" field
	sName = e.Source.Model.Tag
	OpenEmbedded(ThisDatabaseDocument, sName, bReport:=False)
End Sub

Sub OpenEmbedded(odb, sHierachicalName$, bReport As Boolean)
	if bReport then
		container = odb.ReportDocuments
	else	
		container = odb.FormDocuments
	endif
	obj = container.getByHierarchicalName(sHierachicalName)
	obj.open()
End Sub
1 Like

Not in this case. The filter table here is not connected to any field control.

1 Like

Hi Villeroy, thank you for your insight. I do notice that by clicking the button the focus can be taken away.
It is relatively easy to add the name of the form or report to the “additional info” property of the calling button, but where to save the code you put in your post? To “My Macros” → Standard->Module1? I didn’t get it since I am still quite new to Macro.

Good to know, dear Ratslinger! Thank you.