I've got a checkbox .

I have this macro, that works very well for setting a field called “Sortkey” from one called “Name”:

sub setKey (e as object)
dim oDoc, oDrawpage, oForm, oName, oSortKey, oConnection as object
dim wSort as string

oDoc = thisComponent
oDrawpage = oDoc.drawpage
oForm = oDrawPage.forms.getByName("MainForm")
oName = oForm.getByName("txtName")
oSortKey = oForm.getByName("txtSortKey")

wSort = oName.text

if left(wSort, 1) = """" then
   wSort = mid(wSort, 2)
   if right(wSort, 1) = """" then wSort = left(wSort, len(wSort) - 1)
endif
oSortKey.BoundField.updateString(wSort)

end sub

I have absolutely no idea where I found “oSortKey.BoundField.updateString(wSort)”

Now, I want to do something similar with another field, to programmatically set the value of a checkbox. Here is what I have so far:

sub setBlocked (e as object)
dim oDoc, oDrawpage, oForm, oStatus, oShitlist, oConnection as object
dim wCheckBox as boolean

oDoc = thisComponent
oDrawpage = oDoc.drawpage
oForm = oDrawPage.forms.getByName("MainForm")
oStatus = oForm.getByName("txtStatus")
oBlocked = oForm.getByName("cbBlocked")
wCheckBox = InStr(oStatus.text, "permanent") > 0 or InStr(oStatus.text, "suspended") > 0

msgBox(wCheckBox)

oBlocked.BoundField.updateState(wCheckBox)

end sub

I tried updateCheckBox, updateState, updateValue, updateBoolean, and just plain update. Whatever I try, the msgBox fires with the correct Boolean value, but then it comes back with "Object variable not set.

What is it I’m looking for? And where is it documented?

Please always mention your SO, version of LibreOffice and application you are working on.

MRI or another object-inspector to see, wich methods are available for oBlocked

You could find all this commands also in Base Guide. If you use “BoundField” the commands will be executed without parameter ‘c’.
It will depend on the field properties of the datasource. Might be updateBoolean, but as you described it doesn’t work. How did you define the field in datasource?

1 Like

The datasource is a query on an HSQLDB table. That particular field is defined as what the LibreOffice Base table design window calls “Yes/No Boolean.” And Mr. Prin (@gaetanopr) nailed it.

“my SO”? I’m running LibreOffice 7.2.7.2, under what LibreOffice identifies as Linux 5.18 (“Pop!_OS 21.10,” Ubuntu-derived).

1 Like

If you want to programmatically set the value of a checkbox you must use the state property and assign values ​​0 e 1 and not False or True
Try it this way
If wCheckBox = True Then oBlocked.State = 1 Else oBlocked.State = 0

1 Like

Nailed it. Thanks. Although the “= True” part of the IF statement is redundant, given that wCheckBox is already boolean; I used
If wCheckBox Then oBlocked.State = 1 Else oBlocked.State = 0

Although the names given here are somewhat bowdlerized from the actual database and code: the actual names of the control, the database field, and the variables involved are based on something a bit jucier than “blocked.” Namely, “:poop:list.” A term I’d been using since the original ClarisWorks version of the database (back when ClarisWorks included a version of FileMaker), that ran on my old Mac Performa 5215, over a quarter-century ago.