replacing a field name with a variable name

  • Thread starter Thread starter LisaB
  • Start date Start date
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)
....
---------------
 
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,
 
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,
 
Back
Top