473,626 Members | 3,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Novice help with list boxes

Col
Hi - I've never worked with list boxes before. Here's what I'd like to
do - have a list box (or some other control) that allows multiple
selection and stores all the values in one field (can be separated by
commas, line breaks - no preference as long as they are all in one
field). Can a list box do this? If so, how do I get the selections
stored in the field. I've set up the list box with the proper values
and multiple selections enabled, but am clueless about the next step.
And, if a list box won't do what I need it to do, what else could i
used?

Thanks! Colleen

Aug 29 '06 #1
6 1349
Storing denormalized data deliberately? BAD idea. It'll come back to
bite you later on. So make friends with SPLIT, because you're gonna
need it. There's a reason this is a PITA. Because it's a bad idea.
use a subform with a combobox. Then your data is nicely normalized and
everything. If you want to eliminate "used" values, you can do that,
too.

Aug 29 '06 #2
this code will do it...

I wouldn't recommend it, though...

Private Sub cmdAddToTextBox _Click()
Dim strList As String
Dim lbx As Control
Dim varItem As Variant

Set ctl = Me.List0
For Each varItem In ctl.ItemsSelect ed
'---you should use a recordset or currentdb.Execu te strSQL to
insert your records.
strList = strList + ", " + ctl.ItemData(va rItem)
Next varItem

strList = Right$(strList, Len(strList) - 2)
Me.txtListedIte ms = strList

Set ctl = Nothing
End Sub

Aug 29 '06 #3

<pi********@hot mail.comwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
this code will do it...

I wouldn't recommend it, though...

Private Sub cmdAddToTextBox _Click()
Dim strList As String
Dim lbx As Control
Dim varItem As Variant

Set ctl = Me.List0
For Each varItem In ctl.ItemsSelect ed
'---you should use a recordset or currentdb.Execu te strSQL to
insert your records.
strList = strList + ", " + ctl.ItemData(va rItem)
Next varItem

strList = Right$(strList, Len(strList) - 2)
Me.txtListedIte ms = strList

Set ctl = Nothing
End Sub
I have been under the impression that "&" should be used when concatenating
stings not "+". Has this changed?
Aug 29 '06 #4
no, it's just my crap code. You're right, it should.

Aug 29 '06 #5
Col
Hi - can you suggest an alternative for me (since storing multiple
values in one field from a list box is not recommended). My database is
capturing report requests. I want users to identify which fields they
need included in the report - i want them to select from a list of
fields and select as many as they want. I'd like the values stored in
just one field for simplicity for me (I can just look at that field to
know what to include in the report). The database is currently setup so
each potential report field is listed as a yes/no field. It's been very
cumbersome for me to scroll through the list to see what is needed. I
thought have all the report fields listed in one field would be easier
for me to work with. So if they select the following fields - name,
enumber, term date, employment date, BU, location, supervisor - that
those fields can easily stored and retrieved in that record. Thoughts?

pi********@hotm ail.com wrote:
this code will do it...

I wouldn't recommend it, though...

Private Sub cmdAddToTextBox _Click()
Dim strList As String
Dim lbx As Control
Dim varItem As Variant

Set ctl = Me.List0
For Each varItem In ctl.ItemsSelect ed
'---you should use a recordset or currentdb.Execu te strSQL to
insert your records.
strList = strList + ", " + ctl.ItemData(va rItem)
Next varItem

strList = Right$(strList, Len(strList) - 2)
Me.txtListedIte ms = strList

Set ctl = Nothing
End Sub
Aug 30 '06 #6
....use a single field bit sum instead ...the idea is to use the binary
representation of an integer (110001101) to store and retrieve the values of
individual checkboxes ...the following code is just a skeleton but should
give you the idea ...you can use this approach to store the results of a
large number of check boxes in a single field and yet easily derive their
individual yes/no values anytime you need to ...hth

Private Sub chkTest_Click(I ndex AS Integer)
Dim iCount AS Integer
For iCount = 1 TO chkTest.Count
If chkTest(iCount) .Value = vbChecked Then
‘The box is selected, calculate the Base 2 value
lblValue.Captio n = lblValue.Captio n + (2^iCount)
End If
Next iCount
End Sub

‘Decode the value provided in the textbox
Private Sub cmdDecode_Click ()
Dim iCount AS Integer ‘Generic Counter
Dim iValue AS Integer ‘Hold the value to decode

iValue = Val(txtValue.Te xt)

‘Browse each checkboxes in reverse order
For iCount = chkTest.Count To 1 Step –1
‘If the difference between the current iValue and the 2^iCount is
positive
If iValue - (2 ^ iCount) >= 0 Then
‘The current box index was selected
chkTest (iCount).Value = vbChecked
‘Remove the current ‘base 2 power’ from iValue
iValue = iValue - (2 ^ iCount)
End If
Next iCount
End Sub

'note the above is from my code library and thus not complete
'the intent is to give you the idea so that you can build from it

William Hindman

"Col" <cm****@hotmail .comwrote in message
news:11******** *************@m 79g2000cwm.goog legroups.com...
Hi - can you suggest an alternative for me (since storing multiple
values in one field from a list box is not recommended). My database is
capturing report requests. I want users to identify which fields they
need included in the report - i want them to select from a list of
fields and select as many as they want. I'd like the values stored in
just one field for simplicity for me (I can just look at that field to
know what to include in the report). The database is currently setup so
each potential report field is listed as a yes/no field. It's been very
cumbersome for me to scroll through the list to see what is needed. I
thought have all the report fields listed in one field would be easier
for me to work with. So if they select the following fields - name,
enumber, term date, employment date, BU, location, supervisor - that
those fields can easily stored and retrieved in that record. Thoughts?

pi********@hotm ail.com wrote:
>this code will do it...

I wouldn't recommend it, though...

Private Sub cmdAddToTextBox _Click()
Dim strList As String
Dim lbx As Control
Dim varItem As Variant

Set ctl = Me.List0
For Each varItem In ctl.ItemsSelect ed
'---you should use a recordset or currentdb.Execu te strSQL to
insert your records.
strList = strList + ", " + ctl.ItemData(va rItem)
Next varItem

strList = Right$(strList, Len(strList) - 2)
Me.txtListedIte ms = strList

Set ctl = Nothing
End Sub

Aug 30 '06 #7

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

Similar topics

3
2404
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the list boxes'). Users can add and remove items from the list boxes. When the users are adding and removing items, the list boxes are single
8
2563
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and courses are populated. When course is selected, lists of occurrences, groups and
5
4219
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1); System.Data.SqlClient.SqlCommand dbCommand1 = new System.Data.SqlClient.SqlCommand();
3
252
by: Greg Smith | last post by:
Hi I have what I am sure is a really stupid question, but, here goes. I am creating a database application. To allow people to edit records, I run a stored procedure and populate the text boxes on the form. After the data is edited I try to run a stored procedure to update the record. The problem is the click event on the button posts back to the server before the stored procedure runs and I get back the original data before the save....
9
15834
by: natwong | last post by:
Hi All, I'm a newbie in terms of Access and some of its functionality . I've been stuck on this problem for a couple days, even after searching the Web, etc. Currently I have five combo boxes (actually list boxes) that are multiselects in my main form. I need to use these combo boxes to filter a subform within my main form. My combo boxes are as follows: 1. A - 4 select options 2. B - 10 select options 3. C - 4 select options
12
9798
by: ljungers | last post by:
I'm on the home streach of my project and found that my "Reset for New Search" command button not working as desired. What should happen is that when the button is clicked a Event Procedure is run. That event procedure should clear the text boxes that are used for a search query that loads the results into a list box on that same form. When clicked, all is cleared in the text boxes, and the list box is cleared but shows column seperator lines...
0
1333
by: waggledance | last post by:
I was wondering if anyone here might be able to offer me some advice for someone who can only use Macromedia Dreamweaver MX. I am (clearly!) a web design novice so apologies in advance if this is a silly question. I have been asked to build a website to specifications provided by a graphic designer at very short notice. The specifications include the visual appearance of the page, set out with pixel widths, locations of graphics, fonts, etc....
5
1523
by: =?ISO-8859-2?Q?Istv=E1n?= | last post by:
Could somebody suggest me a novice Python list, please? Thanks, Istvan
6
4661
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option for 2 list boxes:- county and nationality, while trying to add a third multi select list box for qualifications search is where i encounter my problem. I've copied the working code from my working list boxes, however it cant seem to pick up the...
0
8262
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
8196
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
8701
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
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
8502
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...
0
7192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
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();...
1
2623
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
1
1807
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.