Field with a macro to set form filter gets empty once filter gives no records

I’m trying to setup an automatic filter which selects a record with a Company having the phone number which contains the typed numbers into the special field box. It works correctly but there is a problematic side effect - it gets empty.
I’ve taken the original example from the Filter from control value article and modified it adding the “lbCoPhone” control in the bottom of the form 149030246117618.odb. To try how it works enter “1” into this control then enter the “0” resulting in “10” which perfectly finds the corresponding record in “Companies” with the corresponding phone number but once you enter the non-existing numbers sequence in this field (e.g. click “2” resulting in “102”) the “lbCoPhone” control gets empty causing inconvenience required to reenter the data again (in the real use case user may wants to correct the entered number instead of entering all the sequence from the beginning again).

Can anybody suggest a workaround for this?

The filter function for the reference:

Sub FreeFilter
    Dim oForm AS OBJECT
    Dim stData AS String
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
    stData = oForm.getByName("lbCoPhone").Text
    oForm.Filter = "( ""PHONE"" LIKE '%" & stData & "%')"
    oForm.Reload()
End Sub

Hello,

The problem lies in the control “lbCoPhone” being on the same form and it gets cleared when oForm.Reload() is executed.

Fix - Create a second main form (in this example called ‘Form’) and move “lbCoPhone” to that form. Then a slight change to the sub:

 Sub FreeFilter
	Dim oForm AS OBJECT
	Dim oForm2 AS OBJECT
	Dim stData AS String
	oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
	oForm2 = ThisComponent.Drawpage.Forms.getByName("Form")
	stData = oForm2.getByName("lbCoPhone").Text
    oForm.Filter = "( ""PHONE"" LIKE '%" & stData & "%')"
    oForm.Reload()
 End Sub

Thanks a lot, Ratslinger, for the idea. I had a thought that the whole form is cleared if the form’s filter has no data selected accordingly to the filter set. Though it still looks a bit strange why should LO clear everything on the form in this case. Anyway, just for anybody else who will read this - the problem is solved in the attached modified application 149030246117618.odb - I’ve moved the control to another root form I’ve created in the same forms drawing. To see it open the form navigator. I created the “SearchForm” there and moved the search field to it, modified the script to search the field there, that’s it, it works!