Full Version: Hide/Show all controls on a form
UtterAccess Forums > Microsoft® Access > Access Forms
gorgeous1
Hi there
I have several access forms of which have several yes/no questions on them, I want to be able to hide all controls on the forms and then only display (Me.SM3.Visible = True) the controls when relevant answers are given, basically a FAQ database.
I have the following code but it doesn't seem to want to work, can anyone please help.
Function EnableDisableControls(strForm As String, intSection As Integer, fEnable As Boolean) As Boolean
' Comments : Enables or disables all controls in the specified section of the specified form
' Parameters: strForm - name of a currently open form
' intSection - number of the section to enable/disable controls in
' fEnable - True to enable controls, False to disable
' Returns : True if successful, False otherwise
'
Dim frmIn As Form
Dim ctlTmp As Control
On Error GoTo err_EnableDisableControls
Set frmIn = Forms(strForm)
For Each ctlTmp In frmIn.Controls
If ctlTmp.Section = intSection Then
On Error Resume Next
ctlTmp.Enabled = fEnable
On Error GoTo err_EnableDisableControls
End If
Next ctlTmp
EnableDisableControls = True
exit_EnableDisableControls:
Exit Function
err_EnableDisableControls:
EnableDisableControls = False
Resume exit_EnableDisableControls
End Function
Sub DisableControls()
'Disable all controls in the detail section of the form named '????'
Dim bOK As Boolean
bOK = EnableDisableControls("CentralFunctions", 0, False)

End Sub
niesz
Welcome to UA Forums!
Can you please tell us specifically what does or does not work as you intended?
gorgeous1
On opening any of the forms I need all the controls/elements hidden until required.
know I can do it by using the Me.SM3.Visible = True method but when you have 20+ controls/elements on a single form it gets messy and confusing.
niesz
I understand your requirements ... I was hoping you'd tell us what about the current procedure you've posted does not work as you intended.
pere_de_chipstick
welcome2UA.gif

In your post you ask to make the controls invisible but you are using :

ctlTmp.Enabled = fEnable

Shouldn't this be

ctlTmp.Visible = fEnable

HTH
gorgeous1
I get no error messages if that is what you are asking. When I open a form all the controls/elements are visable.
This is the third time I have tried to reply, I was tying to attach the database but it will not let me!
gorgeous1
Shouldn't this be
tlTmp.Visible = fEnable
This didn't make any difference!
niesz
Just opening the form would not fire this code. You need to react to an event of some sort and call the function.

Have you tried putting:

Call DisableControls

... in the OnOpen event of the form?


P.S. A DB has to be zipped and <500K to attach to the forum.
gorgeous1
Thanks Niesz that worked (stupid women that I am!!)
niesz
FWIW, I don't think you're stupid at all. Inexperienced, maybe. cool.gif
thumbup.gif
missinglinq
Like Bernie and gorgeous, I'm trying to figure out how setting the Enabled property is affecting the Visibility of the controls!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.