Ask Your Question

Base Form macro not responding.

asked 2021-04-16 05:36:56 +0200

Shaba1 gravatar image

updated 2021-04-16 06:15:09 +0200

Ratslinger gravatar image

I am writing a Database to catalog various picture that I have on my heard drive. I have made a form with various fields on it. image description

I have a listbox (lstbxBrtCtry) that is populated with country names using a sql select distinct statement that queries the worldcites table. The selected country is then put into the {birthCountry) textbox to the left of the list box.

I am trying to populate the (BirthCitylst} listbox based on which city is in the {birthCountry) textbox using a macro.

Here is the macro which I have attached to the (BirthCitylist) listbox when gaining focus event.

Sub pick_city_list
    Dim oForm as Object
    Dim countryText as string
    Dim cityList as Object
    Dim cityBox as Object
    Dim oCountryList as Object
    Dim oCountryBox as Object
REM Determine if the countrylist text box has a value
    oForm = ThisComponent.DrawPage.Forms.GetByName("dsPhotoInfo")
    oCountryBox = oForm.getByName("birthCountry")
    IF NOT IsNull(oCountryBox.text) THEN
End Sub

I am only using MSGBOXES becasue I read somewhere online that ThisComponent cannot be used with the BASICIDE debugger. I I am falling back to the oldest method of debugging and using MSGBOXES becasuse I could not locate a PRINT() function in Libreoffice BASIC.

The problem comes when I save the macro and the form then run the form and select the (BirthCitylist) listbox nothing happens neither message box get called.

can somone please tell me what I am doing worngly


edit retag flag offensive close merge delete



Edited code for clarity.

Would not use:

IF NOT IsNull(oCountryBox.text) THEN


IF oCountryBox.text <> "" THEN

But that is not the entire problem as the code works for me.

Don't know what DB you are using (tested with HSQLDB embedded - bad for embedded images). Don't know what LO version you are using (tested with TDF v7.1.2.2) Don't know what OS you are using (tested with Ubuntu 20.04).

A sample (attached to edited question) would help.

Ratslinger gravatar imageRatslinger ( 2021-04-16 06:20:06 +0200 )edit

Also, you can use the IDE debugger. ThisComponent is only a problem when running the macro from the IDE itself. In this case, the macro is triggered from a form event. Just set your watches and break point.

Ratslinger gravatar imageRatslinger ( 2021-04-16 20:12:59 +0200 )edit

I am using :

Version: (x64) / LibreOffice Community Build ID: fe0b08f4af1bacafe4c7ecc87ce55bb426164676 CPU threads: 4; OS: Windows 10.0 Build 19041; UI render: Skia/Raster; VCL: win Locale: en-US (en_US); UI: en-US Calc: CL Using the HSQL database/

This is link to as zip file which contains the .odb file and a USER/ directory and 4 sub directories contain ONE graphic each. The graphic WILL NOT be embedded in the final database but linked so that I can move them around where I want to.

link text

I hope that is enouigh

Shaba1 gravatar imageShaba1 ( 2021-04-17 01:10:48 +0200 )edit


In your question you stated:

The problem comes when I save the macro and the form then run the form and select the (BirthCitylist) listbox nothing happens neither message box get called.

but I see message box appearing when using the sample you posted.

Also see you have that macro tied to multiple controls.

Ratslinger gravatar imageRatslinger ( 2021-04-17 01:54:40 +0200 )edit

It does not show up for me this is what I get when I just start the form in "run" mode. I use the term run mode for want of a better word. link text

Here is the events dialog box for the BirthCountry listbox

link text

So you can see that no other event uses the pick_city_list macro

Shaba1 gravatar imageShaba1 ( 2021-04-17 03:29:38 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2021-04-19 05:34:40 +0200

Shaba1 gravatar image

[SOLVED] It was my fault. I had to lower the macro security level. There are now four levels. Previous version of LO just had a button to enable macros or not.

edit flag offensive delete link more

answered 2021-04-17 03:57:48 +0200

Ratslinger gravatar image


Only posting this because I need to display images. Your last links ask for me to sign into Google so no, I do not see. In fact here are three controls (as stated in my comment) all tied to the same macro:

image description

image description

image description

And here is the message box on a form when the list box was selected (the other controls with the macro attached do the same): image description

Note that the message is incorrect as the code is incorrect. Noted this in my first comment.

edit flag offensive delete link more


Ratsinger First let me thank you for answering. and helping. Those two links should be open now. they had some default restriction from google that I did not notice. I just checked my version of the form on my machine here and none of those controls have anything associated with their focus event other than BirthCitylist

Ok correction I just looked at the form again and yes two other controls were attached to that same macro. I have now deleted those entries in the events dialog of each control and saved that form and the database Saved the form and saved the database and shut down LibreOffice all together just to be sure. I restarted and checked this two other controls and the macros were gone. I got out of edit mode and "ran" the form and I clicked the down arrow on BirthCitylist and I get a blue highlighted ...(more)

Shaba1 gravatar imageShaba1 ( 2021-04-17 04:51:35 +0200 )edit


Will give this some thought overnight. Have no clue as to your problem. Works for me with LO v7.1.2.2 (don't see this as issue) and tested with both Ubuntu 20.04 and Win 10. Does loop in Win 10 as focus events for list boxes need close examination.

Also, again note that the Basic IDE can be used as I stated in my comment.

Final thought for today is try resetting you user profile. See -> LibreOffice user profile

Ratslinger gravatar imageRatslinger ( 2021-04-17 05:55:13 +0200 )edit


Have you tried resetting the User Profile as mentioned? I appears there is a new post with a similar problem. See -> What might have caused macros to stop working.

Have you installed XRay? It is an Object Inspector.

Ratslinger gravatar imageRatslinger ( 2021-04-18 02:41:01 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2021-04-16 05:36:56 +0200

Seen: 56 times

Last updated: Apr 19