Unknown references in macro

Creating and using forms
Post Reply
GuidoThys
Posts: 10
Joined: Sun Feb 01, 2015 1:33 pm

Unknown references in macro

Post by GuidoThys »

I have created a database "Master" + a form "MasterEdit" and then inserted a combo box "NameSearch" into it, linked to a macro "SearchMacro", which I want to use to search the field "Name" in the database.
In the regular form mode, I can see the data from the field "Name" in all the records in the pull-down list, so the link with the field is OK.
However, when I start typing the search string, I get the following error message: com.sun.star.container.nosuchelementexception.

The reason why is clear: I am using a macro that I found online (https://neowiki.neooffice.org/index.php ... _the_Macro) which obviously contains references and variables that I need to adapt:

Code: Select all

Sub SearchByState

dim oFilter as object
dim oFormCtl as object

oFormCtl = ThisComponent.Drawpage.Forms.getByName("Standard")
oFilter = oFormCtl.getByName("StateSearchListBox")

if oFilter.CurrentValue <> "" then
oFormCtl.Filter = "State LIKE " + "'"+oFilter.CurrentValue+"'"
oFormCtl.ApplyFilter = True
else
oFormCtl.ApplyFilter = False
end if

oFormCtl.Reload
End Sub
I have little experience with macro's and I can't find the syntaxt anywhere online, so I would greatly appreciate a little help.
The error refers to the 0FormCtl-line but I cannot figure out what "Standard"is: is it the name of a field, a database, or something else?
The same probably goes for "StateSearchListBox" on the next line.
I have used the trial-and-error way but that didn't work :oops:

Any of the following three kinds of input would help me a lot:
- an explanation of the variables in the code
- a referrral to a (preferably concise) syntax guide so that I can figure it out myself
- another macro that would do the job.

Thanks very much in advance!
OpenOffice 4.1.3. on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Unknown references in macro

Post by Villeroy »

For macro programming it is inevitable to obtain programming skills at a minimum level.
Search this forum for "power filtering" and you will find a less complicated (but still not trivial) way to implement a filter form.
And the built-in form filter is not too bad.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Unknown references in macro

Post by UnklDonald418 »

Here is a link to your error message.
https://www.openoffice.org/api/docs/com ... ption.html
although I doubt it will be of much help to you.
Anytime you see something like getByName(“Standard”) in macro code it tells you that the macro was written to access a specific control on a specific form. Taking it out of context means it won't work anymore. It might be possible to adapt it to your form, but that requires knowing intimate details about your form, and understanding how to access the API . The learning curve for writing macros is very steep.
Here is a link to an Example setting up a filter without resorting to macros.
viewtopic.php?f=100&t=42845
It is a rather lengthy discussion so scroll to the very bottom and download the example called
LIKE_user_input_filter.odb
to see if that approach would work for you.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply