Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"FIND" routine

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
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
 
If I understand you correctly, It sounds like you may be looking up the wrong column.

e.g If your columns are like such:

Column 0 Column 1 Column 2
IDField, FirstName, LastName

then you will want to change your code from

If List0.Column([red]1[/red], intRow) = strA Then

to

If List0.Column([red]2[/red], intRow) = strA Then

Hope that's what you were looking for.

PDeeney
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top