473,657 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Table field that contains a list.

This has to be simple, but I'm forced to admit that I'm a novice who can't
figure it out.

I have a listbox in a form that allows multiple selections. That works fine.

The problem: I can't figure out how to store the data. I want to store the
items chosen from the listbox in a field for the current record. That means
the table field must store the variable number of text items selected from
the listbox by the user.

Perhaps I'm going about it in the wrong way - I'm open to any suggestions.

Be gentle.
Nov 13 '05 #1
4 2347
What you're trying to do is actually a violation of database normalization
principles, one of which states that each field should contain a single
value.

For this reason, Access will not let you bind a field to a multiselect list
box: only to one that allows single selections. If there's a legitimate
reason for storing the multiple values, you'll have to put code in the
listbox's AfterUpdate event to loop through the list and concatenate all of
the selected values, and then get that concatenated list into the table's
field. (A common approach would be to have a hidden text box that's bound to
the field, and set the hidden text box's value in your listbox's AfterUpdate
event)

To concatenate the fields, use something like:

Dim varItem As Variant
Dim strValues As String

strValues = vbNullString
For Each varItem In Me!MyListBox.It emsSelected
strValues = strValues & Me!MyListBox.It emData(varItem) & ", "
Next varItem

'remove the ", " from the end
If Len(strValues) > 0 Then
strValues=Left$ (strValues,len( strValues)-2))
End If
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Onion" <on***@pmosoft. com> wrote in message
news:gfsWd.6151 4$uc.7949@trndd c08...
This has to be simple, but I'm forced to admit that I'm a novice who can't
figure it out.

I have a listbox in a form that allows multiple selections. That works
fine.

The problem: I can't figure out how to store the data. I want to store the
items chosen from the listbox in a field for the current record. That
means the table field must store the variable number of text items
selected from the listbox by the user.

Perhaps I'm going about it in the wrong way - I'm open to any suggestions.

Be gentle.

Nov 13 '05 #2
I would be inclined to use a main form/subform for this. Then set the
subform to use a combobox. That way, I can look for/count/manipulate
information easily. If you loop through the selected items in the
listbox and write them to a single field, you're denormalizing, and
that could bite you later on. Say for example your listbox contains
ice cream flavors, and you write the result to a text field. Okay, how
many people ordered peach? How many people ordered raspberry? How
many ordered both? Not possible unless you do something to parse out
the data and then you can analyze it. And do you *really* feel like
writing a parser when you shouldn't have to?

What I'm getting at (hopefully nicely) is that going forward with what
you propose is a bad idea. It's just not flexible enough, and won't
serve anything more than your most immediate purposes. You won't be
able to easily query or summarize your results if you store everything
in the same field. And if you can't sort or summarize your data, why
use a database at all?

Nov 13 '05 #3
Thank you. That's the feedback I was looking for - it helps me understand
that my approach was wrong.

I guess to preserve the single field to single value principle, I should
store the multiple listbox selections in another table B, each in a seperate
record with a second field that contains the record ID in table A that each
selection corresponds to.

Sound right?

"Douglas J. Steele" <NOSPAM_djsteel e@NOSPAM_canada .com> wrote in message
news:ZP******** ************@ro gers.com...
What you're trying to do is actually a violation of database normalization
principles, one of which states that each field should contain a single
value.

For this reason, Access will not let you bind a field to a multiselect
list box: only to one that allows single selections. If there's a
legitimate reason for storing the multiple values, you'll have to put code
in the listbox's AfterUpdate event to loop through the list and
concatenate all of the selected values, and then get that concatenated
list into the table's field. (A common approach would be to have a hidden
text box that's bound to the field, and set the hidden text box's value in
your listbox's AfterUpdate event)

To concatenate the fields, use something like:

Dim varItem As Variant
Dim strValues As String

strValues = vbNullString
For Each varItem In Me!MyListBox.It emsSelected
strValues = strValues & Me!MyListBox.It emData(varItem) & ", "
Next varItem

'remove the ", " from the end
If Len(strValues) > 0 Then
strValues=Left$ (strValues,len( strValues)-2))
End If
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Onion" <on***@pmosoft. com> wrote in message
news:gfsWd.6151 4$uc.7949@trndd c08...
This has to be simple, but I'm forced to admit that I'm a novice who
can't figure it out.

I have a listbox in a form that allows multiple selections. That works
fine.

The problem: I can't figure out how to store the data. I want to store
the items chosen from the listbox in a field for the current record. That
means the table field must store the variable number of text items
selected from the listbox by the user.

Perhaps I'm going about it in the wrong way - I'm open to any
suggestions.

Be gentle.


Nov 13 '05 #4
Yup, that's how it should be done. (And as Piet Linden pointed out, a
form/subform setup is the usual interface for this)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Onion" <on***@pmosoft. com> wrote in message
news:UFvWd.8001 2$wc.18809@trnd dc07...
Thank you. That's the feedback I was looking for - it helps me understand
that my approach was wrong.

I guess to preserve the single field to single value principle, I should
store the multiple listbox selections in another table B, each in a
seperate record with a second field that contains the record ID in table A
that each selection corresponds to.

Sound right?

"Douglas J. Steele" <NOSPAM_djsteel e@NOSPAM_canada .com> wrote in message
news:ZP******** ************@ro gers.com...
What you're trying to do is actually a violation of database
normalization principles, one of which states that each field should
contain a single value.

For this reason, Access will not let you bind a field to a multiselect
list box: only to one that allows single selections. If there's a
legitimate reason for storing the multiple values, you'll have to put
code in the listbox's AfterUpdate event to loop through the list and
concatenate all of the selected values, and then get that concatenated
list into the table's field. (A common approach would be to have a hidden
text box that's bound to the field, and set the hidden text box's value
in your listbox's AfterUpdate event)

To concatenate the fields, use something like:

Dim varItem As Variant
Dim strValues As String

strValues = vbNullString
For Each varItem In Me!MyListBox.It emsSelected
strValues = strValues & Me!MyListBox.It emData(varItem) & ", "
Next varItem

'remove the ", " from the end
If Len(strValues) > 0 Then
strValues=Left$ (strValues,len( strValues)-2))
End If
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Onion" <on***@pmosoft. com> wrote in message
news:gfsWd.6151 4$uc.7949@trndd c08...
This has to be simple, but I'm forced to admit that I'm a novice who
can't figure it out.

I have a listbox in a form that allows multiple selections. That works
fine.

The problem: I can't figure out how to store the data. I want to store
the items chosen from the listbox in a field for the current record.
That means the table field must store the variable number of text items
selected from the listbox by the user.

Perhaps I'm going about it in the wrong way - I'm open to any
suggestions.

Be gentle.



Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5830
by: Rob | last post by:
I'm just getting around to using pivot tables and charts. I find the Pivot table interface to be INCREDIBLY frustrating. When I view a table in Design view, then choose Pivot table view, I get the PivotTable Field list, from which I can choose to add fields to the view. 1. How do you get RID of a field once you put it in? I can not right click on anywhere in the view and have ANY of the submenu options be availble. From the PivotTable...
5
25581
by: tpcolson | last post by:
I have a fairly large access 2003 table (200,000) records. Field 'X' is a text field, and contains either no value, 4 digits, 5 digits, or 6 digits. What I need to do is to add two zeros to the left of the records with 4 digits in field 'X', 1 zero to the left of the records with 5 digits in field 'X', and 6 digits for nulls. IE, record 1 field 'X' contains 1234, after this magic, it would contain 001234. Bear in mind, I have ABSOLUTLY...
33
2478
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following criteria: I have a list of about 100 numbers which correspond to the ID field and also another 40 say numbers corresponding to the numbers in the PRODUCT field. I want to show the rows that correspond to both these criteria.
3
3380
by: Darin | last post by:
This is something that on the surface seems like it should be simple, but I can't think of a way to do this. I have a table that is a list of "jobs", which users create and use. It has a single autonumber key field. Within a job, there can be multiple orders. Logically, there'd be an orders table that is a child of the job table. This orders table has a long integer field that matches it to the master job autonumber field. ...
16
3485
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown list and checkbox so that they can make changes. I named these elements as arrays and wish to run an...
76
271963
MMcCarthy
by: MMcCarthy | last post by:
Normalisation is the term used to describe how you break a file down into tables to create a database. There are 3 or 4 major steps involved known as 1NF (First Normal Form), 2NF (Second Normal Form), 3NF (Third Normal Form) and BCNF (Boyce-Codd Normal Form). There are others but they are rarely if ever used. A database is said to be Normalised if it is in 3NF (or ideally in BCNF). These steps are descibed as follows: Note: When attribute...
7
4535
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent records. Should I design a new form for this or can I somehow make this work in the same form. Thanks in advance, john
2
1887
by: seanxtang | last post by:
I am wondering if Access has the capability to do this: I have two tables. In table one, let's say there is a field named "Address" - which contains the normal street address AND a city name; in another table (Table Two) I have a column / field called "city". I want to get all records from Table One which Address column contains a city name that is in Table Two's city list. Does anyone know if Access can do this? Thank you very...
8
24791
by: gurmet | last post by:
I have two tables; 1. Called "Courses" that contains two fields "Course ID" and "Course Name". 2. Called "Sessions" that contains a field called "Course ID". Then I have a form with a combo box that uses the "Course_Name" field for its list and stores the item you select from that list into the "Course ID" field on the "Sessions" table. What I want it to do is use the "Course_Name" as its drop down list but store the associated...
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8612
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.