Disable field unless another field is checked

Hello everyone. I have created a form in Base, and I am trying to have several of the fields to be disabled or invisible unless a certain other field is checked.

In the below screenshot, I would like for the fields Offline Date, Offline Reason/Notes, Location, and Location Date to be disabled or invisible unless Offline is checked.

I know enough to do basic database stuff, but I have no experience with macros. Not saying that I can’t learn, just that if the answer involves macros, you may need to go more in depth with the explanation.

Thank you very much for any help that you fine folks can provide.

Normally you control something like this via a query.
If your query contains only the records with a check mark, you don’t have to hide or disable anything.

Surely that would only work for existing records not for new ones?

All fields are in one form?

SUB Hide(oEvent AS OBJECT)
    oField1 = oEvent.Source.Model 'Your checkbox
	oForm = oField1.Parent
	FOR k = 0 TO oForm.Count - 1
		oField = oForm.getByIndex(k)
			IF oField.ServiceName <> "stardiv.one.form.component.CheckBox" AND  oField.ServiceName <> "stardiv.one.form.component.Hidden" THEN
			oField.EnableVisible = False
		END IF
	NEXT
END SUB

All will be hidden except the “CheckBox” (Hope this is the right name for the component).
You have to set EnableVisible = True when changing row of the form.

I am looking for control at the form level, just because offline status can change often. When a unit comes online, I don’t want to have to uncheck Offline, delete the information in the other fields, then close the form, run a Query, etc. And the same in reverse when a unit goes offline.

I am trying to figure out something like a conditional statement for the other fields, like ENABLED IF OFFLINE=TRUE, or where I would set such a condition.

@RobertG Where would I input this code?

First: You have to create a module for a macro. If you don’t know how this should work: Try with Base Guide.

Macro should be connected to the Checkbox. So you could connect to State of the checkbox. ‘1’ - checked; ‘0’ - unchecked. The macro above doesn’t red oField1.State, but this could be added.

The macro should be connected to “Status changed” (don’t know if this is called so in English version …)

Ok. Thank you for a starting point, I will see what I can figure out.

hello @caffeineglitch,
your conception appears to me seriously flawed!
why include unwanted records in a result set?
the only visible data control will be the check box, leaving the user oblivious of record content.

an obvious solution is to use a query (as suggested by Hrbrgr) in combination with a filter table.
you can then choose to view only checked records, only unchecked records or all records via a list box.
existing records can be edited or deleted and new records can be added.

the attachment is a HSQLDB embedded database, it has two forms fOffline and fOffline_As_Requested.

fOffline_As_Requested:
a clone of your form which shows/hides the unwanted controls.
it uses the macro (Hide) which is similar to the code posted posted by RobertG.
my preference is to show the controls but hide their contents by using corresponding font and background colours.
by enabling/disabling commented lines in the macro called Hide you can check this out for yourself.
the downside is that this invisible text when highlighted by mouse or keyboard is visible but for your needs this is probably immaterial.

fOffline:
a filter form which is simple, intuitive and practical.
because macro use was unavoidable in the form fOffline_As_Requested i have included a small macro (FilterChanged) which simplifies user interaction when filter options change.

DO NOT use both forms at the same time, they each reference the same table.
Offline.odb (25.6 KB)

@cpb You did it! That was exactly what I wanted. fOffline_As_Requested is perfect. Thank you very much.

I am going to spend quite a bit of time going through that Hide Macro and figuring out what it does and how it works. Do you have any suggestions on learning macros, other than general googling online?

For Base: Download the current Base Guide from English documentation | LibreOffice Documentation - LibreOffice User Guides or try directly Chapter 9 Macros

this thread may help
.
the MRI inspection tool is a must have
.
first published by Lulu.com in 2008 and out of print for many years but I found this book indispensable:
OpenOffice.Org Base & Basic By Roberto Benitez
.
it’s best to avoid macros until one thoroughly understands the mechanisms of Base.
the single most important but often overlooked issue is database design/structure.
many of the users coming to this site will never build more than one database, they have limited knowledge/experience but seem to believe that macros are the answer to their prayers.
it’s not worth investing the time and effort required unless you intend build multiple databases.
.
in order to toggle controls between visible/invisible we need the macro, the code is in fact very simple, if the comments are removed then there’s very little left.
incidentally I used enumeration to iterate over the controls just to be different from RobertG and otherwise would have used the For/Next.