J
JP
I have an Access form, and needed help with a list box
that calculated a value assigned to each selection. "Roxie
Aho" was kind enough to provide the following:
(quote)
"The List Box control has a MultiSelect property under the
Other tab on Properties. Help has a good explanation of
how to use it. Select Simple or Extended. My example
works with both.
In the example I added a text box named ListAdd to the
form. The name of the list box is ListBox because that's
what I was able to grab quickly. It just displays name
and a primary key from a table. In the ListBox After
Update event I added the following code:
Private Sub ListBox_AfterUpdate()
Dim ctlList As Control, varItem As Variant
Dim a As Long
' Return Control object variable pointing to list box.
Set ctlList = Me.ListBox
' Enumerate through selected items.
For Each varItem In ctlList.ItemsSelected
' Print value of bound column.
'Debug.Print ctlList.ItemData(varItem)
a = a + ctlList.ItemData(varItem)
Next varItem
'Debug.Print a
ListAdd.Value = a
End Sub
The user can hold down the Control Key while clicking to
select the items he or she wants. At the same time the
Text Box ListAdd shows the sum of the primary key values
as the user selects.
The Text Box control has many properties you can set in
code for display purposes.
The form and example I created has no real purpose. It is
only to show you some capabilities. The code also comes
from Visual Basic Help: Item Data Property and example."
(end quote)
Well, it worked like a charm, despite the fact that I have
no idea what all that means. In the table this list box
refers to, there are two columns. The first contains
numbers which are totalled in a text box as Roxie Aho
described. The second column contains text items, and now
I need to also list these items, as selected, in a second
text box. So, if I select 3 items from the list of 50,
this second text box will display those 3 items.
I've been through the help guide and examples, but just
cannot figure these things out. Any help?
Again, many thanks!
JP
that calculated a value assigned to each selection. "Roxie
Aho" was kind enough to provide the following:
(quote)
"The List Box control has a MultiSelect property under the
Other tab on Properties. Help has a good explanation of
how to use it. Select Simple or Extended. My example
works with both.
In the example I added a text box named ListAdd to the
form. The name of the list box is ListBox because that's
what I was able to grab quickly. It just displays name
and a primary key from a table. In the ListBox After
Update event I added the following code:
Private Sub ListBox_AfterUpdate()
Dim ctlList As Control, varItem As Variant
Dim a As Long
' Return Control object variable pointing to list box.
Set ctlList = Me.ListBox
' Enumerate through selected items.
For Each varItem In ctlList.ItemsSelected
' Print value of bound column.
'Debug.Print ctlList.ItemData(varItem)
a = a + ctlList.ItemData(varItem)
Next varItem
'Debug.Print a
ListAdd.Value = a
End Sub
The user can hold down the Control Key while clicking to
select the items he or she wants. At the same time the
Text Box ListAdd shows the sum of the primary key values
as the user selects.
The Text Box control has many properties you can set in
code for display purposes.
The form and example I created has no real purpose. It is
only to show you some capabilities. The code also comes
from Visual Basic Help: Item Data Property and example."
(end quote)
Well, it worked like a charm, despite the fact that I have
no idea what all that means. In the table this list box
refers to, there are two columns. The first contains
numbers which are totalled in a text box as Roxie Aho
described. The second column contains text items, and now
I need to also list these items, as selected, in a second
text box. So, if I select 3 items from the list of 50,
this second text box will display those 3 items.
I've been through the help guide and examples, but just
cannot figure these things out. Any help?
Again, many thanks!
JP