FindFirst on list box

I am using the FindFirst  method and for each  record found,
I have a list that's contain a id, first name and last name.
on click on the list it take the same id in the edit box for id
 I take an action.
It's seem, When i have the same name it take the first name .
How can i solve this problem ?

Private Sub list0_Click()

Dim rst As Recordset
Set rst = Me.RecordsetClone


rst.FindFirst "[Name]='" & list0.Column(0) & "' And [LastName]='" & list0.Column(1)  & "'"
If rst.NoMatch Then
    MsgBox "There is No Name"
End If

 If Not rst.EOF Then
    Me.Bookmark = rst.Bookmark
 End If


End Sub

Open in new window

Brahim DjouadiAsked:
Who is Participating?
 
Gustav BrockConnect With a Mentor CIOCommented:
I couldn't get your upload to work. It seems hosed somehow.
So, I created a new. It works, though I'm not sure exactly how you intended, as that is not very clear.
example2.accdb
1
 
Gustav BrockCIOCommented:
FindFirst does what it says, finds the first entry that matches.

Include FirstName in the search to find individual names.
1
 
Brahim DjouadiAuthor Commented:
Thank you Gustav Brock
the field [Name] mean the first name
 how can i  solve my problem to take the next name
i'm new in acces
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Gustav BrockCIOCommented:
Well, you can move to the next:

If Not rst.EOF Then
    rst.MoveNext
    If Not rst.EOF Then
        Me.Bookmark = rst.Bookmark
    End If
End If

Open in new window

1
 
Brahim DjouadiAuthor Commented:
the same problem
 MoveNext does nothing

if i have two same names

on click on the list the edit boxes that contain id,firstname and the lastname value it take the same value for the first id,firstname and the lastname

It's seem, When i have the same name and last name it take the first record .
0
 
Gustav BrockCIOCommented:
If you search for something (a combination of fields/values) that is unique, it will find that entry. Otherwise, it will find the first match.
That's by design.
0
 
Brahim DjouadiAuthor Commented:
are there any type to find a solution to do this
example
if i have 5 names like this:
========================
id   -    firstname   -  lastname
1          jhon               helen
2          adam             gebson
3          jhon               helen
4         admin            master
5         jhon                helen
========================

and i have edit box with query for search on event on change
when i search for that name jhon
it will show the three names
and on click on one of them  they take the same id
witch mean it only take the first

how can i make it when i click on any name give me it's  id
0
 
Gustav BrockCIOCommented:
Yes. Use the first field, ID, as the bound column of the listbox.
That will make ID the selected value, and that is unique.
1
 
Brahim DjouadiAuthor Commented:
how can i do that ?

because i think FindFirst accept only strings

i have attached my file can you do that

and thank you
example.mdb
0
 
Brahim DjouadiConnect With a Mentor Author Commented:
Thank You Gustav Brock
you help me a lot with this example file

i will attach the correct file

for helping other user if any one need it or have the same problem
example2.accdb
0
 
Brahim DjouadiAuthor Commented:
All Done
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.