About the Filter Table Method

Hi.
I have

  • Main Form (MF) with ListBox linked to a Filter Table (FT).
  • Sub Form linked to the MF by a SELECT […] :parameter linked to the
    SELECT parameter FROM FT WHERE (the only row).
  • Sub sub Form source = a table, linked to the SF.

All works fine and auto updates via Status Changed of list box:

[...]
    LB.commit() ‘ the list box
    SFC.reload ‘ the sub form
End Sub

But when these forms opens up, of course are displayed the last selected records, as parameter is stored in the FT.
So I want to clear the FT when closing the forms, so nothing shows up on opening before selection in the LB.
Tried the MF events

  • Before unloading
  • When unlosding

but code doesn’t run.

Sub LimparFT(Evt As Object)
    Dim MF As Object, Stmt As Object
    Dim sSQL As String
    MF = Evt.Source
    print "funcionando!"
End Sub

Thanks in advance!

With “Add data only” nothing shows up for selection at LB.
Besides: I think only modifications can be allowed in the Filter Table Method (because there is only one row for each criteria).

Try Tools → Customize of the form document, not an event of the main form.


Here a screenshot of a form with 2 macros: Toolbars of the macros will be hidden when form document will be opened and will be shown again when document is going to be closed.

Yes, it works.
But now how I get the MF’s ActiveConnection (to run the UPDATE)?
I think this event applies to all Forms, right?
So need to check event’s source name. Tried
Formulario = Evt.Source

  • .Model.Name
  • .Name

to check…
Also tried

  • .getByName(“the MF”)
  • .activeConnection

Always “property or method not found”.
:grey_question:

:ok: it’s .Title.
But from that how to access the master form inside it
|__> MasterForm
to get it’s Connection. For not needing to set another specific connection (?)
:thinking:

the attachment uses the tables of a database which was uploaded to this site by a user, I cannot remember by who or when.
it has 3 tables “tFilms”, “tActors” and a junction table “tActorID_FilmID”, I added a filter table.
the data is exactly as found including the duplication of ‘Al Pacino’.
.
a macro ‘ClearFilterOnLoad’ does just that, it’s certainly not the only way your objective can be achieved.
.
if you don’t already have it then download the MRI extension, it’s essential for macro coders Downoad From Here
.
ClearListBoxWhenFormOpens.odb (18.3 KB)

Installed it today. But I has misinterpreting
Tools > Customize > Events
Didn’t pay attention to Save in:
at bottom.
So was thinking first of all one should check event source to know which Document (= Form) was raising the event, like

If Evt.Source.Title = “DB.odb : THEForm” Then
    ' run the code to do an UPDATE to 0 in the FT.

Didn’t have the knowledge to write code like yours.

One last question: how can one avoid the message when closing

Thank you very much!

Remember your first citation with commit/reload?
.
You have to decide, if you wish to commit the data before leaving. If it is only the filter-table you may clear the data.

It commits always at
ListBox Item status changed
to enable auto refreshing Sub Form + Sub Sub Form.
But got it: solution is .updaterow

	LB.commit()
	MF.updaterow ' the ListBox's Form (Master)
	MF.theSubForm.reload ' simpler than mine getByName

as per @cpb 's code :+1:

By the way: clicking in another control than the ListBox also eliminates de msg when closing.

1 Like

When I try to open https://ask.libreoffice.org/uploads/short-url/1W0rj82koTUhNWUwMm5WVJJos4s.odb i get

SQL Status: HY000 The connection to the external data source could not be established. No SDBC driver was found for the URL ‘sdbc:embedded:hsqldb’. at ./connectivity/source/commontools/dbexception.cxx:413