Filter in a Subform

Creating and using forms
Post Reply
vstarc16
Posts: 36
Joined: Sun Feb 10, 2008 7:00 pm
Location: Zagreb, Croatia

Filter in a Subform

Post by vstarc16 »

Hello everybody, I have a subform with table-control in which I need to filter data depending on what is displayed in textbox in main form (text is not entered but only browsed by navigation bar). I can not use form-subform relation because in that case slave field is '=' master field, and I need it to be LIKE. I tried to modify macro (putting the name of the sub form instead of "MainForm") that is used to filter data in table-control when control TextBox is a part of the same form but without success. Here is the macro that should be changed

Code: Select all

Sub Search_by_name
dim oFilter as object 
dim oFormCtl as object 
oFormCtl = ThisComponent.Drawpage.Forms.getByName("MainForm") 
oFilter = oFormCtl.getByName("TextBox") 
if oFilter.Text <> "" then 
oFormCtl.Filter = "Name LIKE " + "'%"+oFilter.Text+"%'" 
oFormCtl.ApplyFilter = True 
else 
oFormCtl.ApplyFilter = False 
end if 
oFormCtl.Reload 
End Sub
I know that it is probably trivial and I recall seeing it in once but could not find it.
OOo 3.1.X on Ms Vista
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Filter in a Subform

Post by DrewJensen »

Sounds as if you don't really want a Master / Slave form relationship at all.

Rather you want to top level dataform controls and use the value in the field to set the filter for the other - then reload that.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
vstarc16
Posts: 36
Joined: Sun Feb 10, 2008 7:00 pm
Location: Zagreb, Croatia

Re: Filter in a Subform

Post by vstarc16 »

Yes Drew, you are right. I need this for a temporary, specific purpose: rechecking some data that are LIKE text in control TextBox. Otherwise, in operational database normal Master/Slave relation is used.
OOo 3.1.X on Ms Vista
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Filter in a Subform

Post by DrewJensen »

ok - do you need help with that macro then?
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
vstarc16
Posts: 36
Joined: Sun Feb 10, 2008 7:00 pm
Location: Zagreb, Croatia

Re: Filter in a Subform

Post by vstarc16 »

Unfortunately Yes. I suppose that something should be changed in the line:

Code: Select all

ThisComponent.Drawpage.Forms.getByName("MainForm") 
but substituting the 'MainForm' with the name of the subform was not helpful.
OOo 3.1.X on Ms Vista
Post Reply