# How to Hide/Unhide Field(s) on a Base Form or a SubForm

I am in need of this control. Since LOBase doesn't have TAB like Access does; So I am thinking have Push Buttons on the top underneath set of fields from different subforms. Issue is too many fields to display at the same time; so I would like to hide the once aren't needed at the present stage of the user flow. Here is an example:

• I have buttons for ADDRESS, CONTACT,NOTEs etc.
• So when pressed Address_Button, only subForm_Address will be visible on the MainForm. CONTACT subForm and NOTEs SubForm will be non-Visible.
• After lot of Google; I found following set of code which will control the background color of a field; now I need to access the property of Visible to set it to be True/False

Dim oForm As Object, oTempAdd1 As Object

oForm=oEvent.Source.Model.Parent REM CODE BOUND TO FORM BUTTON



edit retag close merge delete

Sort by » oldest newest most voted

Most controls have property EnableVisible, which is reflected in the Control dialog box value for Visible (Yes/No). I suggest grouping everything that should be hidden or displayed onto a Form and then iterating through the objects using a macro, toggling the EnableVisible property. SubForm objects don't have the necessary property so they must be excluded, and consider giving everything else that should not be hidden the same suffix at the end of their names-- those are excluded in the code example too if they end with the characters NoHide. This works pretty well in a function that can be used to toggle the EnableVisible property as follows:

Function ToggleShowHide(ShowHideVariable As Boolean )
RootForm = ThisComponent.Drawpage.Forms
MainForm = RootForm.getByName("MainForm")

i = 0

Do While i < MainForm.Count

If Right(MainForm.getByIndex(i).ServiceName, 4) <> "Form" And _
Right(MainForm.getByIndex(i).Name, 6) <> "NoHide" Then
MainForm.getByIndex(i).EnableVisible = ShowHideVariable
End If
i = i + 1

Loop
End Function


You would call the Function from another macro as follows: ToggleShowHide(False) or ToggleShowHide(True). One way would hide and the other would reveal.

Since it also is good form to move the cursor out of a control that is being hidden, you might also use the following at the same time you hide fields:

Cntrllr = ThisComponent.getCurrentController()
Cntrllr.getControl(MainForm.getByName("TargetField").SetFocus()


Please note that if you save the form after running the macro, it will save the then-current state of the shown/hidden controls, but all will be visible at the same time from the Edit mode.

more

How do I upload/attach/send my ODB file for you?

I need to have FIELD level control. So, that I can Hide/UnHide based on user needs FIELDS

( 2015-04-20 04:54:05 +0200 )edit

@MQ-818: I have emailed you. These are Control level commands, and the Controls are bound to database fields. The object MainForm.getByIndex(i) is an individual text box, numeric input, command button or whatever. Alternatively, you can use MainForm.getByName("YourControlName"), but you will need to hard-code the name of every control and it will not work if you change a name or add/remove a control, which is why I suggest the getByIndex` approach for this task.

( 2015-04-21 03:36:45 +0200 )edit