Listbox position code

  • Thread starter Thread starter Robert
  • Start date Start date
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
 
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 <--
 
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.
 
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 <--
 
Would that be
if nz(list0.itemdata) then
If Left(List0.ItemData(Count), 1) >= "h" Then
End If
end if
?
 
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 <--
 
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 <--
 
Back
Top