473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to Set Visibility of TextBoxes Depending on a Multi-Select ComboBox (2010)

I saw the post on how to make one textbox visible if a selection in the combobox was chosen. However I have a multi-selection combobox and each selection within this combobox needs to control the visibility of different textboxes if chosen.

I'm working in version 2010.
Jan 10 '13 #1
18 4439
ADezii
8,834 Expert 8TB
  1. Let us assume the following:
    1. You have 6 Text Boxes named Text1 thru Text6.
    2. You have a Multiselect 'List Box' named lstTest.
    3. lstTest has 3 Items, namely: Choice 1, Choice 2, and Choice 3.
    4. You set the Tag Property of all Text Boxes involved in this process = Test.
  2. To now control the Visibility of the 6 Text Boxes based on the number of Item(s) selected:
    Expand|Select|Wrap|Line Numbers
    1. Dim varItm As Variant
    2. Dim ctl As Control
    3. Dim ctl2 As Control
    4.  
    5. Set ctl = Me![lstTest]
    6.  
    7. 'RESET all Text Boxes with the Tag Property = 'Test' to False
    8. For Each ctl2 In Me.Controls
    9.   ctl2.Visible = ctl2.Tag <> "Test"
    10. Next
    11.  
    12. 'No Item(s) Selected
    13. If ctl.ItemsSelected.Count = 0 Then Exit Sub
    14.  
    15. For Each varItm In ctl.ItemsSelected
    16.   Select Case ctl.ItemData(varItm)
    17.     Case "Choice 1"
    18.       'Make 1st & 3rd Text Boxes Visible
    19.       Me![Text1].Visible = True
    20.       Me![Text3].Visible = True
    21.     Case "Choice 2"
    22.       'Make 2nd & 3rd Text Boxes Visible
    23.       Me![Text2].Visible = True
    24.       Me![Text3].Visible = True
    25.     Case "Choice 3"
    26.       'Make 5th & Last Text Boxes Visible
    27.       Me![Text5].Visible = True
    28.       Me![Text6].Visible = True
    29.   Case Else
    30.     'Do nothing
    31.   End Select
    32. Next varItm
    33.  
Jan 10 '13 #2
NeoPa
32,556 Expert Mod 16PB
I've updated your question for you as Access ComboBoxes do not have a MultiSelect property. As ListBoxes do, we've assumed that's what you meant to say ;-)
Jan 10 '13 #3
Wow, thanks for the quick reply...Actually, I'm using Access 2010 and there is the option for multiSelect property with comboboxes...but I would think it will work the same as each item in the combobox has a value also.
Jan 10 '13 #4
NeoPa
32,556 Expert Mod 16PB
(Blush) I beg your pardon in that case. I'll change it back to reflect your requirement.
Jan 10 '13 #5
No prob. however, the textboxes did not become visible. I put the code under After_Update on the combobox. Is that where it should go?

It is working on the "change" event for the combobox but think I need If statements instead of case. If I choose one or two boxes, it makes all textboxes visible. Also, if they are deselected, the textboxes remain visible.
Just sayin ;)
Jan 10 '13 #6
NeoPa
32,556 Expert Mod 16PB
SeadooRider:
I put the code under After_Update on the combobox. Is that where it should go?
I expect so, yes.

If it isn't working then I suggest you post the actual code you're using. Working with a simple description of what you've done, rather than any actual code, is unnecessarily confusing. Please include all relevant code - especially the procedure wrappings.
Jan 11 '13 #7
Perhaps I don't understand the full code. I get that
(For i = 0 to Listbox1.listcount -5) is items from none up to the amount of items in the listbox. However, I get an error at .list(x) when I try to run the code. list is highlighted with the error Method or data member not found.

Expand|Select|Wrap|Line Numbers
  1. Private Sub listbox1 AfterUpdate()
  2.       Dim str As String
  3.       Dim i As Integer
  4.       For i = 0 To ListBox1.ListCount - 5
  5.           If ListBox1.Selected(i) Then
  6.               str = & ListBox1.List(i) & ", "
  7.           End If
  8.       Next i
  9.       text1 = str
Jan 13 '13 #8
NeoPa
32,556 Expert Mod 16PB
There is no item (Either Property, Method or Event) of a ListBox called List.

At this stage I will link you to Before Posting (VBA or SQL) Code, as that has some very basic instructions that will help get rid of the simpler and more obvious errors in your code (What you learn from the link is likely to prove very helpful to you in future). Compiling your code is a first, and very important, step.

When you have done that, and if you still have any problems outstanding with it, please post back with your new code.
NeoPa:
Please include all relevant code - especially the procedure wrappings.
What I mean by the procedure wrappings is to make sure you include all the relevant code from the line :
Expand|Select|Wrap|Line Numbers
  1. Private Sub listbox1 AfterUpdate()
up to and including the line :
Expand|Select|Wrap|Line Numbers
  1. End Sub
Otherwise, you've described the issue very clearly so I was able to identify exactly what was causing your immediate problem. Unfortunately, there were various others too which you should find by compiling.

Expand|Select|Wrap|Line Numbers
  1. For i = 0 To ListBox1.ListCount - 5
FYI. This code (intentionally or otherwise) will actually ignore the last four (4) lines of your ListBox control. From your description it's not clear that you appreciated this point. Also, if you have less than four items contained therein, it will throw an error.
Jan 13 '13 #9
ADezii
8,834 Expert 8TB
@SeadooRider
The Code that you posted is flawed in several areas. It should look like something similar to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ListBox1_AfterUpdate()
  2. Dim str As String
  3. Dim i As Integer
  4.  
  5. If Me![ListBox1].ItemsSelected.Count = 0 Then Exit Sub
  6.  
  7. With Me![ListBox1]
  8.   For i = 0 To .ListCount - 1
  9.     If .Selected(i) Then
  10.       str = str & .ItemData(i) & ","
  11.     End If
  12.   Next i
  13. End With
  14.  
  15. 'Remove Trailing Comma
  16. str = Left$(str, Len(str) - 1)
  17.  
  18. Me![Text1] = str
  19. End Sub
Jan 13 '13 #10
Seth Schrock
2,965 Expert 2GB
For clarification, the question asks about a combobox, and then it was repeated that the question was about a combobox and not a listbox in post #4. However, there is no Multi-select property in a combobox (A2010 is what I checked in) and the code provided by the OP is in the Listbox1 After_Update event. As Listbox1 would be the default name given to a new listbox control by Access and not what I would expect to be given by the OP to a combobox, I sense that this is in fact a listbox and not a combobox as originally thought by NeoPa in post #3. I have been following this thread for my own edification and would like this clarified so that I can understand what is happening better.
Jan 13 '13 #11
NeoPa
32,556 Expert Mod 16PB
Very good point Seth. I'm a little shocked, if I'm honest, that someone would make such a claim after the idea had already been called into question. I don't often use my A2010 system, so I'm in the hands of others on this, but to have someone blatantly state something which is simply not true is a surprise. I suppose there may be some confusion in their mind as to what is meant be the terms involved.

Nevertheless, even if we assume we're dealing with a ListBox, the question remains. ADezii's code illustrates how to treat each selected item, but simply adds it to a string. We can help the OP with their code only after they post it again after removal of the main, more obvious, bugs.
Jan 13 '13 #12
ADezii
8,834 Expert 8TB
FYI, in Access 2007 you have have a Multi-Select Combo Box as long as it is Bound to a Multi-Value Field.
Jan 13 '13 #13
Seth Schrock
2,965 Expert 2GB
That is interesting ADezii. Access help for A2007 and A2010 doesn't list it as one of the properties available for the combo box, but does for the list box. I will have to try it out though with the multi-value field.
Jan 13 '13 #14
NeoPa
32,556 Expert Mod 16PB
I don't suppose you have any links I could check on that ADezii? I searched, but finding the documentation for Office on the web is difficult as all the returned pages seem to be forum questions. These don't typically help when trying to confirm a technical point, but I found nothing except loads of comments of MVPs and other experts explaining that there is no Multi-Select property for ComboBoxes.

A definitive link would be good for me, but also fairly essential for the thread now the point has been raised again.
Jan 13 '13 #15
ADezii
8,834 Expert 8TB
This is tricky since there appears to be no Documentation on this per say, it exists on in a specific circumstance, and there is no way to explicitly set the Multi-Select Property of the Combo Box. Try the following to get a visual:
  1. Create a Form Bound to a Table containing a Multi-Valued Field.
  2. Create a Combo Box on this Form and Bind it to the Multi-Valued Field.
  3. All Multi-Values will now appear in this Drop Down Combo.
  4. The mechanism for selecting Multiple Values is different, namely: Check Boxes as opposed to Line Select.
  5. In case you are wondering, executing:
    Expand|Select|Wrap|Line Numbers
    1. Debug.print Me![<Combo Box Name>].ControlType
    will return
    Expand|Select|Wrap|Line Numbers
    1. 111
    or the Intrinsic Constant for
    Expand|Select|Wrap|Line Numbers
    1. acComboBox
    .
  6. If I am somehow misinterpreting this, kindly let me know.
Jan 14 '13 #16
NeoPa
32,556 Expert Mod 16PB
As there is limited documentation (and I don't currently have access to such a system), can you post whether or not the ComboBox control you created has a property called MultiSelect, and whether or not it has a property called ItemsSelected. These are the two properties that are normally used to handle multiple selection in a Multi-Select ListBox.

PS. I don't think you're misinterpreting this any more than any of us is. We want to get to the bottom of this definitively and you're providing information that might help (and that none of us knew about until you did so). If it turns out to be irrelevant then so be it, but we need to check it first to determine that. None of us knows already so we're all in the same boat together.
Jan 14 '13 #17
ADezii
8,834 Expert 8TB
@NeoPa
can you post whether or not the ComboBox control you created has a property called MultiSelect
Apparently it does not
whether or not it has a property called ItemsSelected.
Yes, but it does not appear to work in a similar vein as with a List Box

P.S. - Interestingly enough, ItemsSelected can be mimicked as such:
Expand|Select|Wrap|Line Numbers
  1. Dim varItm As Variant
  2. Me![Combo1].SetFocus
  3.  
  4. varItm = Split(Me![Combo1].Text, ",")
Jan 14 '13 #18
NeoPa
32,556 Expert Mod 16PB
Thanks ADezii. So the .Text property reflects a text string of all the individual items concatenated together as a comma separated list. That's straightforward enough, though not a Mulit-Select ComboBox I would suggest.

Nevertheless, considering all of us have been somewhat confused by what is and what isn't, it's perfectly understandable that anyone may get that wrong.

At this point, considering so much confusing conversation has passed under the bridge since SeadooRider has last posted, it seems only sensible to explain what is now expected from them before we can continue to help with their precise problem.
  1. Firstly, follow the instructions in post #9 to tidy up the basics of the code, before then submitting what we need to see.
  2. Confirming exactly what they mean when they indicate they are working with a Multi-Select ComboBox. One would expect a ComboBox with the setup that ADezii has described or a Multi-Select ListBox. As we've seen already, the code for, and the handling of, the two would be very different.

May I add congratulations to all those who have contributed to this thread so far. I doubt any of us individually could have achieved as much as we've managed together.
Jan 15 '13 #19

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

Similar topics

1
by: Oliver Hoehle | last post by:
Hello! This ist the source-code for an editable combobox implemented with HTML,CSS and Javascript. I have tested it with IE and Mozilla. But I don't know, if it will work in other browsers...
4
by: Beeeeeeeeeeeeves | last post by:
I have an ownerdrawn combo box which I am drawing with an image and some text, this is all working beautifully apart from the difference in the Brush I have to draw the background and the text with...
0
by: John Smith | last post by:
Hello all: I think I have tried almost every avenue under the sun to get this to work but to no avail. I have one table, this table has an id column, a last_name column, and a first_name...
4
by: WhiteWizard | last post by:
Alright everyone, I've managed to stump this group 2 or 3 times now. Don't let me down on this one ;) I have a combo box that lists a number of tests to be run. The user would like the option...
0
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number...
2
by: appi | last post by:
Hello, I have created a custom control in VS 2005 using VB.NET. In this Control, there are multiple text- and comboboxes. Two of the textboxes react on the validating event. But when I move from...
3
by: kaosyeti via AccessMonster.com | last post by:
hey... i have an unbound multiselect listbox on a form that i want to use to populate text boxes on that form. so if a user selects the 3rd item in a list of 20, how can i have that item show up...
5
by: martin DH | last post by:
Hello, The details are below, but I have a simple form (Form1) with two objects and a "search" command button. When the two objects are cascading combo boxes (the form creates the parameters for a...
3
by: pipeme | last post by:
Hi I am using Access 2003 and I have a form with 120 textboxes in a grid layout. Depending on a selection made in a combo box, I want to change the visibility of certain textboxes in the grid. ...
1
by: sanndeb | last post by:
I have a combobox like <ComboBox Height="23" HorizontalAlignment="Left" Margin="88,13,0,0" Name="cmbYears" VerticalAlignment="Top" Width="112" SelectionChanged="cmbYears_SelectionChanged"...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.