Listbox position code

R

Robert

I have a listbox whose bound column contains a word, one word per line, in
alphbetical order. I can set the cursor on a line with the following:

Me.List0 = "house"

where the bound column of the line contains "house".

What I would like to know is how to do it if I don't have the exact value.
So if I said "ho" instead of "house" and assuming the "house" line is the
first alphabetcally that starts with ho, it would highlight that line as
well. What is the coding for this?

Robert
 
S

Stefan Hoffmann

hi Robert,
I have a listbox whose bound column contains a word, one word per line, in
alphbetical order. I can set the cursor on a line with the following:

Me.List0 = "house"

where the bound column of the line contains "house".

What I would like to know is how to do it if I don't have the exact value.
So if I said "ho" instead of "house" and assuming the "house" line is the
first alphabetcally that starts with ho, it would highlight that line as
well. What is the coding for this?
Try this:

Dim Count As Long

For Count = 0 To List0.ListCount - 1
If List0.ItemData(Count) Like "ho*" Then
List0.Value = List0.ItemData(Count)
Exit For
End If
Next Count


mfG
--> stefan <--
 
R

Robert

Thanks for your help. I had to modify it because I didn't look at the
request correctly. They only want one letter and if there's nothing there
that starts with h then it should move to the next item on the list. So I
did

If List0.ItemData(Count) Like "h*" or List0.ItemData(Count) >= "h"
Then

which seems to work. Thanks.
 
S

Stefan Hoffmann

hi Robert,
Thanks for your help. I had to modify it because I didn't look at the
request correctly. They only want one letter and if there's nothing there
that starts with h then it should move to the next item on the list. So I
did
If List0.ItemData(Count) Like "h*" or List0.ItemData(Count) >= "h"
Use

If Left(List0.ItemData(Count), 1) >= "h" Then
End If

and ensure that all entries in your list have content.

mfG
--> stefan <--
 
R

Robert

Would that be
if nz(list0.itemdata) then
If Left(List0.ItemData(Count), 1) >= "h" Then
End If
end if
?
 
S

Stefan Hoffmann

hi Robert,
Would that be
if nz(list0.itemdata) then
If Left(List0.ItemData(Count), 1) >= "h" Then
End If
end if
No, I thought of a slightly modified row source of the list box:

SELECT lookupValue, displayField
FROM yourTable
WHERE NOT IsNull(lookupValue)
AND NOT IsNull(displayField)


mfG
--> stefan <--
 
R

Robert

No. This is a crosstab.
Stefan Hoffmann said:
hi Robert,

No, I thought of a slightly modified row source of the list box:

SELECT lookupValue, displayField
FROM yourTable
WHERE NOT IsNull(lookupValue)
AND NOT IsNull(displayField)


mfG
--> stefan <--
 

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