Determining values of listboxes

  • Thread starter Thread starter Jacob Frankham
  • Start date Start date
J

Jacob Frankham

Hi

I need to iterate through a listbox and ascertain if EACH AND EVERY SELECTED
row in the listbox ends in an asterisk * .

If ALL selected values of the listbox end in an asterisk then this affects
the values in the next listbox.

Can anyone advise me how to go about doing this?

Thanks

Jake
 
Look in Access Help under ItemsSelected Collection
(Example). They use the For...Each...Next method.
As for the Asterisk, look in help under the Right()
function. Your results may be something like:

Dim ctl As Control
Dim varItm As Variant
Set ctl = Form1!List1
For Each varItm In ctl.ItemsSelected
If Right(ctl,1)="*" then
' your listbox 2 calcs here
End if
Next varItm
 
-----Original Message-----
Hi

I need to iterate through a listbox and ascertain if EACH AND EVERY SELECTED
row in the listbox ends in an asterisk * .

If ALL selected values of the listbox end in an asterisk then this affects
the values in the next listbox.

Can anyone advise me how to go about doing this?

Thanks

Jake


.

My first suggestion would be to replace the * in the first
list box with some other value. Having characters like
that(i.e. "", *, & etc.) can cause some problems

However, if this is a big problem, I would then do a for
next loop on the select items and determine what the last
character is.

something like this.

Dim i As Variant


For Each i In Me.listbox.ItemsSelected
if Right(CStr(Me.listbox.ItemData(i)), 1) = "*" then
take some action
else
do something else
end if
Next i
 
I am assuming you are wanting to have it check as you stated to see if every
selected item has the asterisks at the end, and if ALL SELECTED ITEMS do,
then do something. I have taken Matt's code and modified it slightly.

Dim i As Variant, x as Long

x = -1
For Each i In Me.listbox.ItemsSelected
if Right(CStr(Me.listbox.ItemData(i)), 1) <> "*" then
x = 0
exit for
end if
Next i
if x then
<perform some action on listbox 2>
end if

Just as Matt pointed out, I would use something else such as maybe "..."
just as how the menu items shows at the end, when it's going onto another
object for further settings or other actions. Using the asterisks (*)
and/or question marks (?) can cause problems cause they are both wildcards
for searches.
 
Hey Guys

Thanks v much for your quick and most helpful responses

I do appreciate it !

Jake
 
Back
Top