ListBox/Control Issue when porting Database to another system

J

Jason

I'm working on a project where I have several ListBoxes on
a Form and I'm setting a Control object to each of them so
I can pass the ListBoxes to a function.

Example:

Dim ctlSource As Control

Set ctlSource = lstBox1

The problem is I want to transverse the data in the ListBox
to see what values are selected by the user via a FOR loop.
The following code works fine on my system at home, but
doesn't when I transport the Access file (.mdb) to the
person's computer who will actually be using the application:

For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
'Run Some Code Here
End If
Next intCurrentRow


It reports an error message of "object doesn't support this
property or method" or something similar, and gets hung up
on the .ListCount portion of the code. I can understand
why it doesn't think it should work, since technically a
control object doesn't have a ListCount property or method,
but if it works fine on my system at home, what could be
the hang up on a different one? We're both using Access
2002. Any help you can offer would be greatly appreciated.
Thanks!
 
A

Allen Browne

Jason, if this is a multi-select list box, traverse the ItemsSelected
collection, and use the ItemData to get the value.
 
J

Jason

Thanks, that actually helped me streamline the code quite a
bit than the way I was doing it.

Actually I found my problem to be a Reference issue with
the code not working on someone else's system. I guess VBA
is just kinda annoying that way. (Searched the rest the
articles and found someone else with a similar issue)

Thanks for the help though! I'll use those properties from
now on, it's much simpler. =)
 

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