Hi. I have two questions ...
(1) I want to use a Listbox to enable the user to select 1 or many items
from the list. However, I'm having trouble figuring out how to find out
t which items have been selected. How can I do that? Given the
listindex, .selected, .itemsselected, .itemdata properties -- I'm
getting confused.
(2) I, actually, have two listboxes on the form and I want to ONLY let
the user select items in one list. The selected items will be used to
create a query and the listboxes are mutually exclusive. In which event
routines should I put logic to either warn the user or disable the other
control. Please keep in mind that I want to make it such that they can
go back and forth between listboxes before they make up their mind and
hit the command button which will fire off the logic to build the query
and do the other stuff that I want done.
THANKS much for your help.
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com *** 9 4910
Susan Bricker wrote: Hi. I have two questions ...
(1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have been selected. How can I do that? Given the listindex, .selected, .itemsselected, .itemdata properties -- I'm getting confused.
Dim varItem As Variant
Dim varValue As Variant
For Each varItem In Me.ListBox.ItemsSelected
'this gets the value of the first column
varValue = Me.ListBox.ItemData(varItem)
Next varItem
For Each varItem In Me.ListBox.ItemsSelected
'in case you need the value in another col besides the first
'remember, column starts at 0, not 1. So 1 is col 2
varValue = Me.ListBox.ItemData(varItem).Column(1)
Next varItem (2) I, actually, have two listboxes on the form and I want to ONLY let the user select items in one list. The selected items will be used to create a query and the listboxes are mutually exclusive. In which event routines should I put logic to either warn the user or disable the other control. Please keep in mind that I want to make it such that they can go back and forth between listboxes before they make up their mind and hit the command button which will fire off the logic to build the query and do the other stuff that I want done.
I suppose you could have a frame with 2 checkboxes; Use List1, Use
List2. From there you could enable/disable the list boxes and the
command button would know which listbox to use based on the frame value. THANKS much for your help.
Regards, SueB
*** Sent via Developersdex http://www.developersdex.com ***
Thanks for the quick response. Your examples of getting the selected
items from the listbox was just what I needed. As for the checkboxes,
good idea. I was trying to avoid another key stroke for the user, but
looks like your idea would be a good plan. Actually, I might look into
using an OptionGroup, since the user will only be able to select from 1
listbox or the other listbox. So, if I put some option buttons in an
optiongroup, if they select option 1 then that automatically will
"unselect" option 2 (and then I'll disable the associated listbox ...
forcing them to only be able to select from one listbox at a time).
Thanks for your ideas.
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com ***
Susan Bricker wrote: Thanks for the quick response. Your examples of getting the selected items from the listbox was just what I needed.
You are welcome.
As for the checkboxes, good idea. I was trying to avoid another key stroke for the user, but looks like your idea would be a good plan. Actually, I might look into using an OptionGroup, since the user will only be able to select from 1 listbox or the other listbox. So, if I put some option buttons in an optiongroup, if they select option 1 then that automatically will "unselect" option 2 (and then I'll disable the associated listbox ... forcing them to only be able to select from one listbox at a time).
Sorry for the confusion. A frame is what I call an option group...since
the name of the option grroup usually begins with Frame. Yeah, I know
what you mean...adding keystrokes...always a pita. I felt that by using
this method your program would know which list box to use and you could
also enable/disable the listbox based on the selection. Sometimes
tradeoffs are required.... Thanks for your ideas.
Regards, SueB
*** Sent via Developersdex http://www.developersdex.com ***
Hey, Salad...
Is there a way to "unselect" items in a listbox, programmatically?
Here's what I want to (and I've been trying to to this while debugging
the form, but I've been unsuccessful) ...
I have the option buttons in an options group: 1 button for the first
listbox and 1 button for the otgher listbox.
Let's say the user selects optionbutton 1 and enables the first listbox.
Then they select a few items in the first listbox.
Then they decide (before hitting the command button to generate the
query) that they really want to use the 2nd list box. So, they hit the
other option button, which will disable listbox 1 and enable listbox 2.
However, the items that were selected in listbox 1 are still
highlighted. I want to get those highlighted items unhighlighted
(unselected).
Any ideas?
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com ***
If you have two listboxes, lst1 and lst2 and their MultiSelect
properties are set to either simple or extended, use their AfterUpdate
events to disable the listbox you want to exclude, e.g.:
Private Sub lst1_AfterUpdate()
If lst1.ItemsSelected.Count > 0 Then
lst2.Enabled = False
Else
lst2.Enabled = True
End If
End Sub
Private Sub lst2_AfterUpdate()
If lst2.ItemsSelected.Count > 0 Then
lst1.Enabled = False
Else
lst1.Enabled = True
End If
End Sub
To iterate through the items the user actually selected when they click
the command button use something like the following code (note that
this shows only what is in the bound column of the enabled listbox):
Dim lst As ListBox
Dim var As Variant
Dim strItems As String
If lst1.Enabled Then
Set lst = lst1
Else
Set lst = lst2
End If
For Each var In lst.ItemsSelected
strItems = strItems & lst.ItemData(var) & ","
Next
MsgBox "You selected items " & strItems
If you need to use the value of a column other than the bound column
from the enabled listbox use the column property instead of the
ItemData property. For example, if you wanted to use the value in the
third column of the enabled listbox rather than the bound column,
replace
lst.ItemData(var)
with:
lst.Column(2,var)
in the above code (note that columns are 0 based so the 2 above refers
to the 3rd column).
HTH,
Bruce
A global Thank you to all who replied. I'm getting lots of good
suggestions and learning along the way. Thanks, again.
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com ***
SueB wrote: Hey, Salad...
Is there a way to "unselect" items in a listbox, programmatically? Here's what I want to (and I've been trying to to this while debugging the form, but I've been unsuccessful) ...
Sure
Let's say you have a multiselect listbox. And you want all items
selected to be set to unselected. In some event you could have code
that looks like this
Dim varItem As Variant
For Each varItem In Me.ListBoxName.ItemsSelected
Me.ClientList.Selected(varItem) = False
Next varItem I have the option buttons in an options group: 1 button for the first listbox and 1 button for the otgher listbox.
Let's say the user selects optionbutton 1 and enables the first listbox. Then they select a few items in the first listbox.
Then they decide (before hitting the command button to generate the query) that they really want to use the 2nd list box. So, they hit the other option button, which will disable listbox 1 and enable listbox 2. However, the items that were selected in listbox 1 are still highlighted. I want to get those highlighted items unhighlighted (unselected).
I would clear out the selections for both listboxes when you go to a new
record. Or else have a command button to clear out the selected
entries. I would not clear it out by selecting which listbox to use
(see clear out code above)
I can see your dilemma but I'd not do that. I try, as much as possible,
to have sympathy and empathy for the poor user. If I can do as much as
possible to fill in values or make their keystrokes less then I feel I
succeed.
So if a user selects ListBox2, and has selected the items from ListBox1,
and now decides ListBox1 is the right one, if you've cleared it out then
the person needs to reselect all of the items.
Let's say you have 2 listboxes; Listbox1/2. Lets say you have an option
group (Frame1) with 2 checkboxes, you could do something like this
Me.ListBox1.Enabled = (Me.Frame1 = 1)
Me.ListBox2.Enabled = (Me.Frame1 = 2)
based upon the selection.
Now, you have a command button to press when the selections are pressed.
And your code does something like
Dim strSQL As String
If Me.Frame1 = 1 then
strSQL = ...
Else
strSQL = ....
endif
...process something
Any ideas?
Regards, SueB
*** Sent via Developersdex http://www.developersdex.com ***
Well...I'm not Salad, but I like to keep things simple too...
If your listbox's MultiSelect property is set to Extended, simply
requerying the listbox will clear it, e.g.
lst1.Requery
If set to Simple, the code Salad provided works well.
HTH,
B This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alex Stevens |
last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms
and microsoft.public.dotnet.framework.windowsforms.controls to no avail so
apologies for the cross-posting.
Hi,
I'm...
|
by: Simon Templar |
last post by:
I need the following functionality: With 2 listboxes populated from a
database with the SAME data, I need any of the listboxes to stop displaying
the option when selected at the other listbox. Eg:...
|
by: demo |
last post by:
Hi
I got two tables, people and events. Each have a .name and a .ID.
In a third table, participation, I have a many to many connection
between the two, conection people to events.
In a...
|
by: Scot Niklos via AccessMonster.com |
last post by:
Sorry if it is way to much information but I'm trying to cover all bases
Access 97
A= combobox that queries Distributor
B= combobox that limits customers by distributor in a
C= combobox that...
|
by: bill yeager |
last post by:
I have several template columns inside of a datagrid.
Inside of these template columns are databound listboxes:
<asp:TemplateColumn HeaderText="Crew Chiefs">
<ItemTemplate>
<asp:listbox...
|
by: Terry D |
last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle
back end). The page uses the standard VS.NET grid to display the
records from a particular table. The user can edit certain...
|
by: Ryan Ternier |
last post by:
I have two listboxes, and allow users to move items between them via the
following function:
function SwitchList(fbox, tbox){
var arrFbox = new Array();
var arrTbox = new Array();
var...
|
by: Dag |
last post by:
Hello there! I have a problem here. For many of you it
would not be a problem at all, but I am new in
programming...so here is the question:
I have a form with two listboxes in it....Listbox1...
|
by: Dominic Isaia |
last post by:
I am trying to simulate a multicolumn listbox. I need a way to link
two listboxes together so that if you scroll one listbox the other
scrolls with it. Any help will be appreciated.
Thanks,...
|
by: Thelma Roslyn Lubkin |
last post by:
I am still having trouble trying to use a popup form to allow user to
set filters for the main form.
The main form is based on a single table.
The popup contains 5 listboxes, so the user can...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |