Check for value in List Box

S

Silvio

Hello, I have the code below to compare a value from control vs. the content
of a list box (column 1), however it does not work. Any idea how to get it to
work?

If Me.DocumentsList.Column(1).Value = me.MyCompany Then
....

Thank you,
Silvio
 
D

Dirk Goldgar

Silvio said:
Hello, I have the code below to compare a value from control vs. the
content
of a list box (column 1), however it does not work. Any idea how to get it
to
work?

If Me.DocumentsList.Column(1).Value = me.MyCompany Then


The listbox Column property doesn't have a Value property. Maybe this is
what you want:

If Me.DocumentsList.Column(1) = Me.MyCompany Then

Be aware also that in code, columns are numbered starting from 0, so that
the first column of the list box is .Column(0). If you intended to check
the first column of the list box, then you would need this version:

If Me.DocumentsList.Column(0) = Me.MyCompany Then

Of course, if the column you want to check is the list box's bound column,
then you don't need to refer to the .Column property at all:

If Me.DocumentsList = Me.MyCompany Then
 
M

Marshall Barton

Silvio said:
Hello, I have the code below to compare a value from control vs. the content
of a list box (column 1), however it does not work. Any idea how to get it to
work?

If Me.DocumentsList.Column(1).Value = me.MyCompany Then
...

If your column 1 is the first column, then use Column(0)
 
S

Silvio

Thanks guys but it does not work. Keep in mind that I DON'T make ANY
selection from the list box the evaluation process starts from the control
me.mycompany

I guess the list box need to be treated as record set??!!
 
D

Dirk Goldgar

Silvio said:
Thanks guys but it does not work. Keep in mind that I DON'T make ANY
selection from the list box the evaluation process starts from the control
me.mycompany

I guess the list box need to be treated as record set??!!


I don't know about Marshall, but I don't understand what you're doing, or
what you're trying to accomplish, and you haven't said in what way it
doesn't work, so there is nothing to "keep in mind". May I suggest again
that you explain what "doesn't work" means to you, and what it is you want
to do, and then I'm sure we can solve your problem.

Your remark about treating the list box as a recordset hints at a
possibility for what you may intend, but you need to spell it out.
 

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