473,765 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiselect listbox

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 in a text box? then, how can i
have a second selected item show up in a different text box, without
affecting the 1st one? (lboxOptions, txtboxOptions0, txtboxOptions1, etc..)

--
Greg

Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200705/1

May 11 '07 #1
3 3627
On Fri, 11 May 2007 13:50:38 GMT, "kaosyeti via AccessMonster.c om" <u15580@uwewrot e:
>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 in a text box? then, how can i
have a second selected item show up in a different text box, without
affecting the 1st one? (lboxOptions, txtboxOptions0, txtboxOptions1, etc..)
A multiselect listbox exposes an ItemsSelected collection which you can use, but it's not ordered by the user's choice.
I'm not sure how you'd determine the "first" choice vs the "second" choice, unless you store that information in
variables/arrays etc ... you could perhaps trigger this off the Click event of the listbox ...

See this link: http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx
Scott McDaniel
scott@takemeout _infotrakker.co m
www.infotrakker.com
May 11 '07 #2
i have it close to working, but i've run into one problem. i have code in
the onclick and beforeupdate events to load the info into textboxes on the
same form. the problem is that i want to limit the listbox to 8 choices max,
and when the 9th is selected, a message box pops up to indicate that 8 is the
limit. the problem is, even though i'm trying to cancel at the beforeupdate
event, it still selects the 9th item. here's my code:

Private Sub lboxOptions_Cli ck()
Dim frm As Form
Dim ctl As Control
Dim i As Long
Dim varItm As Variant
Dim strOptionCode As String

Dim currCount As Long

If booOpened Then
i = 0
numSelected = 0
booOpened = False
End If
Set frm = Forms!formNewVe hicleFinder
Set ctl = frm!lboxOptions
If ctl.ItemsSelect ed.Count numSelected Then
For Each varItm In ctl.ItemsSelect ed
currCount = ctl.ItemsSelect ed.Count
strOptionCode = DLookup("[optioncode]", "tblNewOptions" , "[option]
= " & Chr(34) & ctl.ItemData(va rItm) & Chr(34))
Me.Controls("tx tboxoption" & i).Value = strOptionCode
i = i + 1
Next varItm
numSelected = numSelected + 1
Else
numSelected = numSelected - 1
Me.Controls("tx tboxoption" & numSelected).Va lue = ""
End If
End Sub

Private Sub lboxOptions_Bef oreUpdate(Cance l As Integer)
If numSelected = 8 Then
Call MsgBox("Too many options were selected.", vbExclamation,
"Selection Error")
Cancel = -1
Me.lboxOptions. Undo
End If
End Sub

where booOpened is set to true in the form-open event and it, along with
numselected are set as public variables at the top of the code for the form.
what am i missing?

Scott McDaniel wrote:
>>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 in a text box? then, how can i
have a second selected item show up in a different text box, without
affecting the 1st one? (lboxOptions, txtboxOptions0, txtboxOptions1, etc..)

A multiselect listbox exposes an ItemsSelected collection which you can use, but it's not ordered by the user's choice.
I'm not sure how you'd determine the "first" choice vs the "second" choice, unless you store that information in
variables/arrays etc ... you could perhaps trigger this off the Click event of the listbox ...

See this link: http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx

Scott McDaniel
scott@takemeou t_infotrakker.c om
www.infotrakker.com
--
Greg

Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200705/1

May 12 '07 #3
i got it working with the following in the beforeupdate event:

Dim n As Long
If numSelected = 8 Then
n = Me.lboxOptions. ListIndex
If Me.lboxOptions. Selected(n) = False Then
numSelected = numSelected - 1
Me.Controls("tx tboxoption7").V alue = ""
Cancel = True
Else
Cancel = True
Call MsgBox("Too many options were selected.", vbExclamation,
"Selection Error")
Me.lboxOptions. Selected(n) = False
End If
End If

but now i realize what you meant with regard to first choice, second choice.
since i was clicking down the list when i was testing this, i just was
clearing out the last textbox (numbered 0-7), rather than the correct textbox.
so if a user selects 6 items, then unselects the 2nd one, i'm dumping the 6th
one. how would you suggest hitting this with a variable/array solution
(keeping in mind i know nothing about arrays). thanks.

ka******@comcas t.net wrote:
>i have it close to working, but i've run into one problem. i have code in
the onclick and beforeupdate events to load the info into textboxes on the
same form. the problem is that i want to limit the listbox to 8 choices max,
and when the 9th is selected, a message box pops up to indicate that 8 is the
limit. the problem is, even though i'm trying to cancel at the beforeupdate
event, it still selects the 9th item. here's my code:

Private Sub lboxOptions_Cli ck()
Dim frm As Form
Dim ctl As Control
Dim i As Long
Dim varItm As Variant
Dim strOptionCode As String

Dim currCount As Long

If booOpened Then
i = 0
numSelected = 0
booOpened = False
End If
Set frm = Forms!formNewVe hicleFinder
Set ctl = frm!lboxOptions
If ctl.ItemsSelect ed.Count numSelected Then
For Each varItm In ctl.ItemsSelect ed
currCount = ctl.ItemsSelect ed.Count
strOptionCode = DLookup("[optioncode]", "tblNewOptions" , "[option]
= " & Chr(34) & ctl.ItemData(va rItm) & Chr(34))
Me.Controls("tx tboxoption" & i).Value = strOptionCode
i = i + 1
Next varItm
numSelected = numSelected + 1
Else
numSelected = numSelected - 1
Me.Controls("tx tboxoption" & numSelected).Va lue = ""
End If
End Sub

Private Sub lboxOptions_Bef oreUpdate(Cance l As Integer)
If numSelected = 8 Then
Call MsgBox("Too many options were selected.", vbExclamation,
"Selection Error")
Cancel = -1
Me.lboxOptions. Undo
End If
End Sub

where booOpened is set to true in the form-open event and it, along with
numselected are set as public variables at the top of the code for the form.
what am i missing?
>>>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
[quoted text clipped - 11 lines]
>>scott@takemeo ut_infotrakker. com
www.infotrakker.com
--
Greg

Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200705/1

May 12 '07 #4

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

Similar topics

3
3290
by: arthur-e | last post by:
Hi I'm trying to use a multiselect listbox to limit records in a report. My version at work is 97 but now at home I'm using Access2002- I know I can't go backwards ( to use this or similar code at work) anyway: msListBox - listnames unbound report - rptD Code is from the Microsoft Access 97 Developer's handbook 'PILastFirst' is the keyfield selected in the listbox - the bound
2
6368
by: Sally | last post by:
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I want to do this as the selections are being made not after-the-fact after all selections are made. Thanks! Sally
2
3357
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 variable data. Any clues as to how I can write several items to an SQL statement from a multiselect listbox to update a report? Thanks in anticipation Cassie
2
6076
by: Alan Lane | last post by:
Hello world: I'm using Access 2003. I have 2 listboxes. One is a single column. The other has two columns. I can use Dev Ashish's code (thanks Dev!) from the Access MVP Website to accumulate the values from the bound column of a MultiSelect listbox, so that I can include them in a SQL query that will then be the recordsource for a report. This gives me 2 of the 3 values I need to put into the SQL query. However, I can't get the non...
6
1711
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 page load for updation, i have to reload the selected items again with the same string "1/3/6/8" to be selected in my multiselect list box. Its asking me to convert object to int... for list selection. but how to achieve this..?...
2
1954
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 webform, when there is already admission data. I need the populated list box (lbx_comorb) to show the items that were previously selected for this admission. The selected comorb data is stored in another datatable (dt_ptComorb). If anyone can...
2
1599
by: ttime | last post by:
I've got a form that uses a multiselect listbox. When a user is selected from a combo box, values are populated into this listbox associated with that user. The problem is, if one person has say 10 entries in the listbox, and selects the last 3-4, and the next user only has 2 entries, those last 3-4 rows are still highlighted in the listbox. This introduces null values into my code which is definitely not good. I've tried using...
5
4256
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 query - Query1), the query returns my results proper. But when the two objects are cascading combo-then-multiselect listbox (the perferred format in this case), the query always returns zero records. Tables: COMPILE (contains the records to be...
1
1852
by: asharma0001 | last post by:
Hi all, I was wondering whether somebody might be able to help me with a question I have on a MS Access Database I'm building. I have created a search form with a few multiselect listboxes. What I'd ultimately like is for the selection(s) in one listbox to filter the second listbox, but am struggling to find a way to do this. I have looked at some of the other solutions on this forum but not been able to find one that works on my database....
0
9568
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
9404
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
10007
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
9835
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
7379
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
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
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
3532
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.