By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,200 Members | 1,754 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,200 IT Pros & Developers. It's quick & easy.

Show/Hide ComboBoxe/s base on a tick box answer

P: 5
Hello all,

A question from someone who dabbles in Access.
Is it possible to hide or ghost out a combo box (or set of them) on a Form, and only have them appear as a usable option if a tick box option that is also on the form is ticked or marked as true ??....

I am asking this as I want to prevent people entering the data into these combo boxes unless they have selected this tick box. I have a few queries that primarily look at the Yes/No option of the tick box when filtering information, and then subsequently pulls up the information to display from the field linked to the combo box/es.

I would imagine that it would be an after update event on the Tickbox command, if -1, show the combo boxes etc.

I hope that this gives enough information, if not,let me know and I will elaborate as required.

Thanks in advance for any assistance you are able to provide.

Cheers

TimC
Jul 6 '06 #1
Share this Question
Share on Google+
7 Replies


100+
P: 179
The first thing you do is go into the properties for the combobox, and set "visible" to false. In the form's design view, right click on the combobox, and select properties. Scroll down to the "visible" field. While still in properties, change the name field to whatever name you want to call the combobbox. Close the combobbox properties.

Then you are going to create an event procedure for the check box. While still in design view for the form, right click on the checkbox and choose "Build Event", and select "Code Builder". The following code will appear:

Private Sub checkboxname_Click()

End Sub

For an example, if you named your combobox "Combobox1", then type the following code between the 2 lines:

Me.Combobox1.visible=True

So, it should now read:

Private Sub checkboxname_Click()
Me.Combobox1.visible=True
End Sub

Hope this works. Good Luck.
comteck
Jul 9 '06 #2

P: 5
Thanks for the reply and information Comteck - much appreciated - and it is working as you thought it would.

It probably will work in it's current format - I'll have to test it on the labrats at work over the following couple of days.. :-) But if I may pursue this a bit further

Is it possible to expand the underlying code to keep the ComboBoxes visible once a true value is recorded on the Checkbox? (to allow these values to be seen if the information on the form is reviewed at a later time) - and I am shooting in the dark here when I write something like...

Private Sub EquipmentProblems_Check_BeforeUpdate() {Or ??which commmand}
If Me.EquipmentProblems_Check = True (?? or -1) Then
Me.Equip_Probs_1.Visible = True
Me.Equip_Probs_2.Visible = True
Me.Equip_Probs_3.Visible = True
End If
End Sub

I have tried the above code basically as formated above (and have removed the event procedurre for on Check_Click as it seemed to be messing with the above code - no errors though), but at this stage the code does not display the Combo boxes)

Any thoughts on this would be valued
Cheers
TimC
Jul 11 '06 #3

P: 5
Mucking about with the code as below, it is nearly working how I thought I wanted it to... but it still requires a previuosly checked (true) checkbox to be unchecked and then checked to force the update and show the Comboboxes again

Private Sub EquipmentProblems_Check_BeforeUpdate(Cancel As Integer)

If Me.EquipmentProblems_Check = True Then
Me.Equip_Probs_1.Visible = True
Me.Equip_Probs_2.Visible = True
Me.Equip_Probs_3.Visible = True
End If
If Me.EquipmentProblems_Check = False Then
Me.Equip_Probs_1.Visible = False
Me.Equip_Probs_2.Visible = False
Me.Equip_Probs_3.Visible = False
End If

End Sub

Does anyone have a suggestion to get the combo boxes to show from the outset if the Checkbox is true (from an episode of previous data entry) for that particular record ?

Regards
TimC
Jul 11 '06 #4

100+
P: 179
Is the checkbox bound to anything? If not, try adding a checkbox field in your table, and bound it to the checkbox on the form. You can then check for the value of the checkbox. You can still name the checkbox "EquipmentProblems_Check".

Instead of building the code on "Before Update", try opening the properties for the form, and using "On Current".
Also, I don't normally use If Then. I use Select Case wherever possible.

Private Sub EquipmentProblems_Check_OnCurrent(Cancel As Integer)
Dim selEquipProb as Boolean
selEquipProb=Me.EquipmentProblems_Check

Select Case selEquipProb

Case "True"
Me.Equip_Probs_1.Visible = True
Me.Equip_Probs_2.Visible = True
Me.Equip_Probs_3.Visible = True

Case "False"
Me.Equip_Probs_1.Visible = False
Me.Equip_Probs_2.Visible = False
Me.Equip_Probs_3.Visible = False

End Select

End Sub

If this doesn't work, then try adding a button, and using "On Click". In this case, the code would be created under the button instead of the checkbox.

Private Sub btnEquipmentProblems_OnClick(Cancel As Integer)
Dim selEquipProb as Boolean
selEquipProb=Me.EquipmentProblems_Check

Select Case selEquipProb

Case "True"
Me.Equip_Probs_1.Visible = True
Me.Equip_Probs_2.Visible = True
Me.Equip_Probs_3.Visible = True

Case "False"
Me.Equip_Probs_1.Visible = False
Me.Equip_Probs_2.Visible = False
Me.Equip_Probs_3.Visible = False

End Select

End Sub

Not sure if either of these will work. However, I'm quite sure you have the correct code.

Good Luck
comteck
Jul 11 '06 #5

P: 5
Thanks Comteck,
I will give it a burl over the next day or so, and give you feedback on how it goes...

Just FYI - yes the checkbox is bound to in an underlying table (same as the combo boxes)....
Thanks for the tip for use of OnCurrent - It is these sort of things that you miss as a self taught Access user (and I really need to take a write VBA code course, as I tend to get lost in the heavy stuff from time to time. A mate that has been working on this project has more of a VBA brain than me, but we both are lacking when it comes to knowledge of the different VBA commands available).
I was using the If Then scavenged from some other code in the same form (that a 3rd person wrote in the database), threw it in to see if it would work :-P

So thanks again for the help

TimC
Jul 13 '06 #6

P: 5
An update.....
The on current option - I couldn't seem to get it to work dynamically (ie update when flicking to the next form...) but putting the Select Case in place instead of the If staements still seemed to work a treat.

I'll probably leave it as it is now, as this is in escence what I was after (the ability for the dynamic update fits nicely in the obsesive/compulsive streak that I tend to get every now and then.... :-)

Thanks

TimC
Jul 17 '06 #7

ChaseCox
100+
P: 294
The first thing you do is go into the properties for the combobox, and set "visible" to false. In the form's design view, right click on the combobox, and select properties. Scroll down to the "visible" field. While still in properties, change the name field to whatever name you want to call the combobbox. Close the combobbox properties.

Then you are going to create an event procedure for the check box. While still in design view for the form, right click on the checkbox and choose "Build Event", and select "Code Builder". The following code will appear:

Private Sub checkboxname_Click()

End Sub

For an example, if you named your combobox "Combobox1", then type the following code between the 2 lines:

Me.Combobox1.visible=True

So, it should now read:

Private Sub checkboxname_Click()
Me.Combobox1.visible=True
End Sub

Hope this works. Good Luck.
comteck

I found this comment very useful for what I wanted to do, which is hide pages on my form. I did however update the code, so that if the box is uncheked, the page will disapear.

Expand|Select|Wrap|Line Numbers
  1. Private Sub chkvoy2_AfterUpdate()
  2.  
  3.  If chkvoy2 = True Then
  4.         Me.Voyager2.Visible = True
  5.  Else
  6.         Me.Voyager2.Visible = False
  7.  
  8.  End If
  9. End Sub
  10.  
Where Voyager2 is my page name, and chkvoy2 is check box name.
Feb 6 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.