Hi
I have a list box consisting of 5 columns and many rows. I want to create a FIND routine that will let the user find a record(row) in the listbox.
So far I have got the following:
Dim intRow As Integer
Dim cntl As Control
Dim rst As DAO.Recordset
Dim sql As String
Dim strA As String
strA = Nz(InputBox("Enter Last Name", "Cancel"
)
Set cntl = Me!List0
sql = "select LastName from BlackBerryRecord where LastName = '" & strA & "'"
Set rst = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
If rst.NoMatch = False Then
rst.MoveFirst
For intRow = 0 To cntl.ListCount - 1
If List0.Column(1, intRow) = strA Then
List0.Selected(intRow) = True
Exit For
End If
Next intRow
End If
Set rst = Nothing
It does work if I look for a number, but it comes to the string (last name) it does not work
Please advise
I have a list box consisting of 5 columns and many rows. I want to create a FIND routine that will let the user find a record(row) in the listbox.
So far I have got the following:
Dim intRow As Integer
Dim cntl As Control
Dim rst As DAO.Recordset
Dim sql As String
Dim strA As String
strA = Nz(InputBox("Enter Last Name", "Cancel"
Set cntl = Me!List0
sql = "select LastName from BlackBerryRecord where LastName = '" & strA & "'"
Set rst = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
If rst.NoMatch = False Then
rst.MoveFirst
For intRow = 0 To cntl.ListCount - 1
If List0.Column(1, intRow) = strA Then
List0.Selected(intRow) = True
Exit For
End If
Next intRow
End If
Set rst = Nothing
It does work if I look for a number, but it comes to the string (last name) it does not work
Please advise