Unknown references in macro

Creating and using forms

Unknown references in macro

Postby GuidoThys » Sun Nov 13, 2016 3:53 pm

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   Expand viewCollapse view
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
oFormCtl.ApplyFilter = False
end if

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
Posts: 10
Joined: Sun Feb 01, 2015 1:33 pm

Re: Unknown references in macro

Postby Villeroy » Sun Nov 13, 2016 4:31 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Posts: 28536
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Unknown references in macro

Postby UnklDonald418 » Mon Nov 14, 2016 6:28 am

Here is a link to your error message.
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.
It is a rather lengthy discussion so scroll to the very bottom and download the example called
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.6 & LibreOffice - Windows 10 Professional
Posts: 1326
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Return to Forms

Who is online

Users browsing this forum: No registered users and 1 guest