473,396 Members | 1,998 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,396 software developers and data experts.

Display Multiselect on list box

344 Expert 100+
Hi,
I am using Access 2003
I have seen some threads on how to select multiple values from a list box, but how do I display the selected options back again (Last time I used Access in anger, you could not multi-select at all)

This is what I have. A demographic survey form, with over 100 questions, most of which can have multiple answers. At the moment, each answer is stored in the form as a seperate y/n field. Apart from the in-elgance of this solution, Access tells me I have two many fields.

What I would like to do is have a lookup table for each question, with two columns, first column is A,B,C,D etc, second column is the potential answer.
eg A Glass, B Knife, C Scissors etc

Displaying this on the form as a list box, I can pick up the options selected and store in the table the combination, say ADEG

What I cant work out how to do is to display the list box on the form, highlighting the previous selected values from my table field values of "ADEG"

Can this be done in Access 2003 with a bound field, or easily in code?
Jun 8 '07 #1
8 2837
ADezii
8,834 Expert 8TB
Hi,
I am using Access 2003
I have seen some threads on how to select multiple values from a list box, but how do I display the selected options back again (Last time I used Access in anger, you could not multi-select at all)

This is what I have. A demographic survey form, with over 100 questions, most of which can have multiple answers. At the moment, each answer is stored in the form as a seperate y/n field. Apart from the in-elgance of this solution, Access tells me I have two many fields.

What I would like to do is have a lookup table for each question, with two columns, first column is A,B,C,D etc, second column is the potential answer.
eg A Glass, B Knife, C Scissors etc

Displaying this on the form as a list box, I can pick up the options selected and store in the table the combination, say ADEG

What I cant work out how to do is to display the list box on the form, highlighting the previous selected values from my table field values of "ADEG"

Can this be done in Access 2003 with a bound field, or easily in code?
Is your request to store multiple selections of the 1st Column Values in a 2 Column List Box as a String, then save this to the underlying Table? e.g.
Expand|Select|Wrap|Line Numbers
  1. Col1    Col2
  2. A       Glass
  3. B       Knife
  4. C       Scissors
  5. D       Bottle
  6. E       Howitzer
  7. F       Lead Pencil
  8.  
If the User selects A, B, D, and F, store ABDF in the underlying Table?
Jun 9 '07 #2
Lysander
344 Expert 100+
Is your request to store multiple selections of the 1st Column Values in a 2 Column List Box as a String, then save this to the underlying Table? e.g.
Expand|Select|Wrap|Line Numbers
  1. Col1    Col2
  2. A       Glass
  3. B       Knife
  4. C       Scissors
  5. D       Bottle
  6. E       Howitzer
  7. F       Lead Pencil
  8.  
If the User selects A, B, D, and F, store ABDF in the underlying Table?
Storing ABDF in the underlying table is ok, but what I want to do is when the user looks at the record in the future, the form will pick up the ABDF from the table and highlight the respective entries in the list.
Jun 10 '07 #3
ADezii
8,834 Expert 8TB
Storing ABDF in the underlying table is ok, but what I want to do is when the user looks at the record in the future, the form will pick up the ABDF from the table and highlight the respective entries in the list.
This can be done, and as soon as I get a chance, I'll show yoou how.
Jun 10 '07 #4
FishVal
2,653 Expert 2GB
Hi,
I am using Access 2003
I have seen some threads on how to select multiple values from a list box, but how do I display the selected options back again (Last time I used Access in anger, you could not multi-select at all)

This is what I have. A demographic survey form, with over 100 questions, most of which can have multiple answers. At the moment, each answer is stored in the form as a seperate y/n field. Apart from the in-elgance of this solution, Access tells me I have two many fields.

What I would like to do is have a lookup table for each question, with two columns, first column is A,B,C,D etc, second column is the potential answer.
eg A Glass, B Knife, C Scissors etc

Displaying this on the form as a list box, I can pick up the options selected and store in the table the combination, say ADEG

What I cant work out how to do is to display the list box on the form, highlighting the previous selected values from my table field values of "ADEG"

Can this be done in Access 2003 with a bound field, or easily in code?

It seems to me that normalized db structure in your case should be something like this.

tblQuestions
.keyQuestionID (PK, Long(Autonumber))
.txtQuestion (Text)

tblAnswerVariants
.keyAnswerVariantID (PK, Long(Autonumber))
.keyQuestionID (FK,Lookup(tblQuestions))
.txtAnswerVariant (Text)

tblUsers
.keyUserID (PK,Long(Autonumber)
.txtName (Text)

tblUserAnswers
.keyUserAnswerID (PK, Long(Variant))
.keyUserID (FK, Lookup(tblUsers))
.keyAnswerVariantID (FK, Lookup(tblAnswerVariants))
Jun 10 '07 #5
ADezii
8,834 Expert 8TB
Hi,
I am using Access 2003
I have seen some threads on how to select multiple values from a list box, but how do I display the selected options back again (Last time I used Access in anger, you could not multi-select at all)

This is what I have. A demographic survey form, with over 100 questions, most of which can have multiple answers. At the moment, each answer is stored in the form as a seperate y/n field. Apart from the in-elgance of this solution, Access tells me I have two many fields.

What I would like to do is have a lookup table for each question, with two columns, first column is A,B,C,D etc, second column is the potential answer.
eg A Glass, B Knife, C Scissors etc

Displaying this on the form as a list box, I can pick up the options selected and store in the table the combination, say ADEG

What I cant work out how to do is to display the list box on the form, highlighting the previous selected values from my table field values of "ADEG"

Can this be done in Access 2003 with a bound field, or easily in code?
I experimented with some coding techniques, and arrived at a solution but first a couple of Assumptions:
  1. The Main Form name is frmMain.
  2. Tha Main Table Name is tblMain.
  3. The List Box name is lstAnswers. It has 2 Columns, Bound Column = 1, and Multi Select = Extended. the 1st Column will be a single character Answer as A, B, C, ... and the 2nd Column will contain a brief Description.
  4. txtAnswer - A Text Box on the Form that will receive the dynamically built Answer String for each Selection made, e.g. If the user selects A, B, D, and G this Field on the Form will appear as A ==> AB ==> ABD ==> and finally ABDG. txtAnswer is Bound to an [Answer] Field in tblMain.
  5. This is all meant to be a Generic Template to help you accomplish your specific task at hand, make all necessary substitutions wherever appropriate.
  1. In the AfterUpdate() Event of your List Box, place the following code. This code will concatenate (Answer only) all values selected by a User and place them in [txtAnswer] as they are selected.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub lstAnswers_AfterUpdate()
    2. Dim varItem As Variant, frm As Form, ctl As ListBox
    3. Dim strBuiltAnswer As String
    4.  
    5. Set frm = Forms!frmMain
    6. Set ctl = frm![lstAnswers]
    7.  
    8. For Each varItem In ctl.ItemsSelected
    9.   strBuiltAnswer = strBuiltAnswer & ctl.ItemData(varItem)
    10. Next varItem
    11.  
    12. Me![txtAnswer] = strBuiltAnswer
    13. End Sub
  2. The following code segment is to be placed in the Current() Event of the Form as indicated. It will parse the value in txtAnswer character by character, and select the appropriate entries in the List Box. This will be done for each individual Record, which is why the code is placed in this Event.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Current()
    2. Dim S As Integer
    3.  
    4. 'Before anything else, you must clear any Selections in the List Box
    5. 'Items may also be selected from the previous Record
    6. For S = 0 To Me![lstAnswers].ListCount - 1
    7.   Me![lstAnswers].Selected(S) = False
    8. Next S
    9.  
    10. If IsNull(Me![txtAnswer]) Then Exit Sub
    11.  
    12. Dim strLongAnswer As String, intNoOfListItems As Integer
    13. Dim T As Integer
    14.  
    15. intNoOfListItems = Me![lstAnswers].ListCount
    16. strLongAnswer = Me![txtAnswer]
    17.  
    18. For S = 0 To intNoOfListItems - 1
    19.   Me![lstAnswers].Selected(S) = False
    20. Next S
    21.  
    22. For T = 1 To Len(strLongAnswer)
    23.   For S = 0 To intNoOfListItems - 1
    24.     If Me![lstAnswers].Column(0, S) = Mid$(strLongAnswer, T, 1) Then
    25.       Me![lstAnswers].Selected(S) = True
    26.     End If
    27.   Next S
    28. Next T
    29. End Sub
  3. This code provides the logic as to how to solve the 1 specifc problem that you mentioned. It makes no other assumptions about how your data is structured and as to whether or not it is Normalized.
  4. Good luck and let me know how you make out!
Jun 10 '07 #6
Lysander
344 Expert 100+
I experimented with some coding techniques, and arrived at a solution but first a couple of Assumptions:
  1. The Main Form name is frmMain.
  2. Tha Main Table Name is tblMain.
  3. The List Box name is lstAnswers. It has 2 Columns, Bound Column = 1, and Multi Select = Extended. the 1st Column will be a single character Answer as A, B, C, ... and the 2nd Column will contain a brief Description.
  4. txtAnswer - A Text Box on the Form that will receive the dynamically built Answer String for each Selection made, e.g. If the user selects A, B, D, and G this Field on the Form will appear as A ==> AB ==> ABD ==> and finally ABDG. txtAnswer is Bound to an [Answer] Field in tblMain.
  5. This is all meant to be a Generic Template to help you accomplish your specific task at hand, make all necessary substitutions wherever appropriate.
  1. In the AfterUpdate() Event of your List Box, place the following code. This code will concatenate (Answer only) all values selected by a User and place them in [txtAnswer] as they are selected.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub lstAnswers_AfterUpdate()
    2. Dim varItem As Variant, frm As Form, ctl As ListBox
    3. Dim strBuiltAnswer As String
    4.  
    5. Set frm = Forms!frmMain
    6. Set ctl = frm![lstAnswers]
    7.  
    8. For Each varItem In ctl.ItemsSelected
    9.   strBuiltAnswer = strBuiltAnswer & ctl.ItemData(varItem)
    10. Next varItem
    11.  
    12. Me![txtAnswer] = strBuiltAnswer
    13. End Sub
  2. The following code segment is to be placed in the Current() Event of the Form as indicated. It will parse the value in txtAnswer character by character, and select the appropriate entries in the List Box. This will be done for each individual Record, which is why the code is placed in this Event.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Current()
    2. Dim S As Integer
    3.  
    4. 'Before anything else, you must clear any Selections in the List Box
    5. 'Items may also be selected from the previous Record
    6. For S = 0 To Me![lstAnswers].ListCount - 1
    7.   Me![lstAnswers].Selected(S) = False
    8. Next S
    9.  
    10. If IsNull(Me![txtAnswer]) Then Exit Sub
    11.  
    12. Dim strLongAnswer As String, intNoOfListItems As Integer
    13. Dim T As Integer
    14.  
    15. intNoOfListItems = Me![lstAnswers].ListCount
    16. strLongAnswer = Me![txtAnswer]
    17.  
    18. For S = 0 To intNoOfListItems - 1
    19.   Me![lstAnswers].Selected(S) = False
    20. Next S
    21.  
    22. For T = 1 To Len(strLongAnswer)
    23.   For S = 0 To intNoOfListItems - 1
    24.     If Me![lstAnswers].Column(0, S) = Mid$(strLongAnswer, T, 1) Then
    25.       Me![lstAnswers].Selected(S) = True
    26.     End If
    27.   Next S
    28. Next T
    29. End Sub
  3. This code provides the logic as to how to solve the 1 specifc problem that you mentioned. It makes no other assumptions about how your data is structured and as to whether or not it is Normalized.
  4. Good luck and let me know how you make out!
That looks just what I want, will try it out when I get to the office and let you know.

As for having the tables normalised, yes, I can that view point, but this particular survey form, with its multiple answers, is one of many and all the look up tables have to have exacatly the same format due to another constraint (Having to have all the answers in multiple languages)
Jun 11 '07 #7
Lysander
344 Expert 100+
That looks just what I want, will try it out when I get to the office and let you know.

As for having the tables normalised, yes, I can that view point, but this particular survey form, with its multiple answers, is one of many and all the look up tables have to have exacatly the same format due to another constraint (Having to have all the answers in multiple languages)
Works a dream, thanks
Jun 11 '07 #8
ADezii
8,834 Expert 8TB
Works a dream, thanks
You're quite welcome. It was, however, a little tricky!
Jun 11 '07 #9

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

Similar topics

2
by: Cassie Pennington | last post by:
I am trying to write various items from a multiselect list box to an SQL statement to update a report, without success. SQL only appears to accept hard-coded data or control values from a form, not...
1
by: Danny | last post by:
I like the combo box because you can scroll through items nicely, but the list box just has the navigation where you can go up and down. I am trying to allow the user to multiselect items. With...
1
by: Jillian Cee | last post by:
I have a multiselect list box (simple). I need to find out how to get Access to recognise my multiple selections firstly (I believe) then I want these selections to go into a query so that I can...
1
by: tod4 | last post by:
Hi, My problem: I have query with value klient and product. On my form Im using multiselect box as filter of klient value. Now I would like to use second multiselect on this form for product...
6
by: ¿ Mahesh Kumar | last post by:
Hi groups, Control name : ListboxID (lstCertification), selection mode=mutliselect. On Pageload i'm assinging string lstSplit="1/3/6/8" of the previously selected listindex id's. Now on the...
2
by: Steph | last post by:
I have created a multiselect list box control (lbx_comorb) that is populated from a datatable (dt_ptAdmission). The list box populates now problem at all. However the issue is when I load the...
2
by: twill005 | last post by:
Hi, I have created a DB containing server information for multiple servers. I used the multiselect function to select multiple softwares that are on an individual server, but I can't get my...
1
by: Redbeard | last post by:
I am a newbie running Access 2003. A couple of weeks back a member named ADezil help me write a code that let a , MultiSelect Listboxs that run a Query on a Form (many thanks). I have used this...
5
by: erbrose | last post by:
Hey all, newbie to vb here. I've created a listbox (called lst_county) that gets populated from a Select * From Table in Oracle on load. I've set the MultiSelect to 2 -Extended. I've got some code...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.