Full Version: Use Option Group on Form to show/hide data on form
UtterAccess Forums > Microsoft® Access > Access Forms
megilonline
I have an option group on a form which encompasses the various sections of the laboratory i work in. What I want to do is show/hide certain fields on the form based on the users input of the option group. For example, for a person working in the WIDGET Section - show the fields related to WIDGETS (#oftests, #ofreports, etc.)and not the other sections. I am assuming this needs VBA code in the _Afterupdate event. Thanks in advance for your help.
ark
fkegley
Yes, probably a Select Case on the Option Group's value:
SELECT CASE Me.NameOfOptionGroupControl
Case 1
' code here to make controls visible Me.NameOfControl.Visible = "Yes"
Case 2
etc.
END SELECT
You might also need code in other events to hide the controls again.
megilonline
Thank you for your quick reply. I tried the following code, but it says that the 'Object doesn't support this property or method" I am not sure if I am missing something or if there is another way to approach this.
Private Sub optWidget_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Me.optSection
Case 1
Me.numberTests.Visible = Yes
End Select
End Sub
Thanks again.
fkegley
Is optSection the name of the Option Group or the name of one of the options within the group?
megilonline
optSection is the name of the Option Group
ptWidget is an option within the group
numbertests is a field with the visible option set to 'No' on the form
Thanks.
Mark
ScottGem
You want the code in the AFTER UPDATE event of the Option group, not on a specific member of that group
megilonline
Thanks Frank and Scott. I finally got it to work. You were right Scott about putting it in the _Afterupdate of the Group. The working code for the option group is below:
Private Sub optSection_AfterUpdate()
Select Case Me.optSection
Case 1
Me.numberExemplar.Visible = True
Me.numberHair.Visible = False
Case 2
Me.numberExemplar.Visible = False
Me.numberHair.Visible = True
End Select
End Sub
Oreally appreciate the quick response I received for my question. You guys rock.
Mark
ScottGem
glad to assist
megilonline
Sorry, one other question. Is there a way i can make the "....Visible = True" value stick for that record. I noticed when I close the record and reopen it, the default's for the visiblity of the fields are set again to 'No'. Therefore, the values of the fields are not viewable. Thanks in advance. I know I'm a pest now.
ark
ScottGem
Is optSection bound to a field? If it is you can run the same code in the On Current event.
megilonline
Yeah, optSection is bound to a field. I'm leaving from work soon. I'll give it a try first thing in the morning and let you know. Thanks.
ark
megilonline
The option group and the field do not have the _On Current Event listed. Do I need to paste the code into the subForm _ On Current Event. If so what would that look like. Thanks.
ark
ScottGem
Controls do not have an On Current event. That is solely a Form event. You have to look at the form event list. The code should go in the On Current event of the form the option group is on.
megilonline
Scott:
orry, playing with code the whole morning and I just figured it out. Now the active option stays highlighted and the related fields are visible on the form. Thanks again. I posted code below:
Private Sub Form_Current()
Select Case Me.optSection
Case 1
Me.numberExemplar.Visible = True
Me.numberHair.Visible = False
Case 2
Me.numberExemplar.Visible = False
Me.numberHair.Visible = True
End Select
End Sub
Private Sub optSection_AfterUpdate()
Select Case Me.optSection
Case 1
Me.numberExemplar.Visible = True
Me.numberHair.Visible = False
Case 2
Me.numberExemplar.Visible = False
Me.numberHair.Visible = True
End Select
End Sub
Mark
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.