Scroll a list box to selected item

  • Thread starter Thread starter Nelson
  • Start date Start date
N

Nelson

I have code that selects an item in a list box that works fine (below) but I
would like to add code to scroll down to the selected item to show it.
Anyone know how I would do that?
TIA
Nelson

If OpenArgs <> "" Then
For i = 0 To PatientList.ListCount - 1
If PatientList.ItemData(i) = OpenArgs Then
PatientList.Selected(i) = True
Exit For
End If
Next i
If i = PatientList.ListCount Then
DoCmd.Close
MsgBox "There are no claims to print for this patient."
End If
End If
 
I have code that selects an item in a list box that works fine (below) but I
would like to add code to scroll down to the selected item to show it.
Anyone know how I would do that?
TIA
Nelson

If OpenArgs <> "" Then
For i = 0 To PatientList.ListCount - 1
If PatientList.ItemData(i) = OpenArgs Then
PatientList.Selected(i) = True
Exit For
End If
Next i
If i = PatientList.ListCount Then
DoCmd.Close
MsgBox "There are no claims to print for this patient."
End If
End If

Assuming the bound column of the list box is text datatype,
try something like this?

If Not IsNull(Me.OpenArgs) Then
For i = 0 To PatientList.ListCount - 1
If PatientList.ItemData(i) = OpenArgs Then
PatientList.Selected(i) = True ' Why this line?
PatientList= OpenArgs ' *** Add this line
Exit For
End If
Next i
End If

The selected name should appear in the list box.
 
Fred,

Thanks for the reply. 'PatientList = OpenArgs' did not work. I forgot to
mention that ListBox.Mutiselect is set to extended (3)

Nelson
 
Back
Top