list box value - get index or automatically select

jatfill

Registered User.
Local time
Today, 13:00
Joined
Jun 4, 2001
Messages
150
Is there a way to get the index number of a list box row without the row being selected by passing the bound column value into VBA?

Here's my example:

If I have a row in a list box like this:

A1 Apples
B2 Oranges
D3 Tangerines
X4 Pineapple

Assuming I want to be able to grab the index number of the "Tangerines" row by looking it up with the D3 bound column value.

The idea is to automatically select a row with VB based on other selected criteria, but I think I can only automatically select a row in a listbox by referencing the index number of that row...?

I hope this makes sense, I'm not sure I'm explaining it correctly, so please let me know if I can help clarify. Thanks!

[This message has been edited by jatfill (edited 02-28-2002).]
 
I figured this out, so I thought I'd share:

Code:
Dim stVar As Long

 stVar = Forms!srchForm!lstSearch

DoCmd.OpenForm frmName, , ,

DoCmd.GotoControl "lstBox"
Dim i As Integer
    For i = 1 To Forms!frmName!lstBox.ListCount - 1
        If Forms!frmName!lstBox.Column(0, i) = stVar Then
          Forms!frmName!lstBox.Selected(i) = True
          Exit Sub
        End If
    Next
 

Users who are viewing this thread

Back
Top Bottom