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

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 1330
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.ItemsSelected
'---you should use a recordset or currentdb.Execute strSQL to
insert your records.
strList = strList + ", " + ctl.ItemData(varItem)
Next varItem

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

Set ctl = Nothing
End Sub

Aug 29 '06 #3

<pi********@hotmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.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.ItemsSelected
'---you should use a recordset or currentdb.Execute strSQL to
insert your records.
strList = strList + ", " + ctl.ItemData(varItem)
Next varItem

strList = Right$(strList, Len(strList) - 2)
Me.txtListedItems = 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********@hotmail.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.ItemsSelected
'---you should use a recordset or currentdb.Execute strSQL to
insert your records.
strList = strList + ", " + ctl.ItemData(varItem)
Next varItem

strList = Right$(strList, Len(strList) - 2)
Me.txtListedItems = 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(Index 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.Caption = lblValue.Caption + (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.Text)

‘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*********************@m79g2000cwm.googlegro ups.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********@hotmail.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.ItemsSelected
'---you should use a recordset or currentdb.Execute strSQL to
insert your records.
strList = strList + ", " + ctl.ItemData(varItem)
Next varItem

strList = Right$(strList, Len(strList) - 2)
Me.txtListedItems = 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
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...
8
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...
5
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);...
3
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...
9
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...
12
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....
0
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...
5
by: =?ISO-8859-2?Q?Istv=E1n?= | last post by:
Could somebody suggest me a novice Python list, please? Thanks, Istvan
6
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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?

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.