replacing a field name with a variable name

L

LisaB

I want to pass the name of a list box on my form to a function. How do I
make the following work using the variable name??
------------
Public Sub MatchAll (listName as string)
Dim Selection as Variant
Dim Item as string
Dim txtListName as string

txtListName = "lst" + listName
....

For each selection in txtListName.ItemsSelected
Item = txtListName.ItemData(Selection)
....
---------------
 
G

George Nicholson

If this procedure is on the same form as you are calling it from:

Me.Controls(txtListName).ItemsSelected

If not (and maybe even if it is), then I suggest you change the procedure
argument to listbox (which will also change how you call it as well):

Public Sub MatchAll (lbo as Listbox)
.......
For each selection in lbo.ItemsSelected

HTH,
 
L

LisaB

Thank You
George Nicholson said:
If this procedure is on the same form as you are calling it from:

Me.Controls(txtListName).ItemsSelected

If not (and maybe even if it is), then I suggest you change the procedure
argument to listbox (which will also change how you call it as well):

Public Sub MatchAll (lbo as Listbox)
......
For each selection in lbo.ItemsSelected

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top