Find correct record after user using down arrow

S

Song Su

My cboFind will show [Last Name] and [First Name]. I use wizard to create
following code.

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Last Name] = '" & Me![cboFind] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.cboFind.BackColor = -2147483633
Me.Last_Name.SetFocus
End Sub

However, if use uses down arrow to move to different first name (same last
name), my record selector only points to the first match of last name.

How to let record point to correct record?

Thanks.
 
B

Bob Quintal

My cboFind will show [Last Name] and [First Name]. I use
wizard to create following code.

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Last Name] = '" & Me![cboFind] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.cboFind.BackColor = -2147483633
Me.Last_Name.SetFocus
End Sub

However, if use uses down arrow to move to different first
name (same last name), my record selector only points to the
first match of last name.

How to let record point to correct record?

Thanks.
rs.FindFirst "[Last Name] = '" & Me![cboFind] & "' AND "
"[Firsat Name] = '" & Me![cboFind].column(1) & "'"

column() is a zero-based index into the combobox's columns. If
[First name] is not the second column, adjust accordingly.
 
B

Bob Quintal

Hi, Bob:

Thanks for your help. My [First Name] is 2nd column (right
after [Last Name]). When I use your

rs.FindFirst "[Last Name] = '" & Me![cboFind] & "' AND
""[First Name] = '" & Me![cboFind].column(1) & "'"

it gave me following error message:
Run-time error '3077'
Syntax error in string in expression

- Song

I left in too many quote marks when I cut and pasted. Try

rs.FindFirst "[Last Name] = '" & Me![cboFind]
& "' AND [First Name] = '" & Me![cboFind].column(1) & "'"

Sorry about that.

Bob Quintal said:
My cboFind will show [Last Name] and [First Name]. I use
wizard to create following code.

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Last Name] = '" & Me![cboFind] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.cboFind.BackColor = -2147483633
Me.Last_Name.SetFocus
End Sub

However, if use uses down arrow to move to different first
name (same last name), my record selector only points to the
first match of last name.

How to let record point to correct record?

Thanks.
rs.FindFirst "[Last Name] = '" & Me![cboFind] & "' AND "
"[Firsat Name] = '" & Me![cboFind].column(1) & "'"

column() is a zero-based index into the combobox's columns.
If [First name] is not the second column, adjust accordingly.
 
S

Song Su

Hi, Bob:

Thanks for your help. My [First Name] is 2nd column (right after [Last
Name]). When I use your

rs.FindFirst "[Last Name] = '" & Me![cboFind] & "' AND ""[First Name] = '" &
Me![cboFind].column(1) & "'"

it gave me following error message:
Run-time error '3077'
Syntax error in string in expression

- Song

Bob Quintal said:
My cboFind will show [Last Name] and [First Name]. I use
wizard to create following code.

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Last Name] = '" & Me![cboFind] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.cboFind.BackColor = -2147483633
Me.Last_Name.SetFocus
End Sub

However, if use uses down arrow to move to different first
name (same last name), my record selector only points to the
first match of last name.

How to let record point to correct record?

Thanks.
rs.FindFirst "[Last Name] = '" & Me![cboFind] & "' AND "
"[Firsat Name] = '" & Me![cboFind].column(1) & "'"

column() is a zero-based index into the combobox's columns. If
[First name] is not the second column, adjust accordingly.
 
S

Song Su

Works great! Thanks.

Bob Quintal said:
Hi, Bob:

Thanks for your help. My [First Name] is 2nd column (right
after [Last Name]). When I use your

rs.FindFirst "[Last Name] = '" & Me![cboFind] & "' AND
""[First Name] = '" & Me![cboFind].column(1) & "'"

it gave me following error message:
Run-time error '3077'
Syntax error in string in expression

- Song

I left in too many quote marks when I cut and pasted. Try

rs.FindFirst "[Last Name] = '" & Me![cboFind]
& "' AND [First Name] = '" & Me![cboFind].column(1) & "'"

Sorry about that.

Bob Quintal said:
My cboFind will show [Last Name] and [First Name]. I use
wizard to create following code.

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Last Name] = '" & Me![cboFind] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.cboFind.BackColor = -2147483633
Me.Last_Name.SetFocus
End Sub

However, if use uses down arrow to move to different first
name (same last name), my record selector only points to the
first match of last name.

How to let record point to correct record?

Thanks.

rs.FindFirst "[Last Name] = '" & Me![cboFind] & "' AND "
"[Firsat Name] = '" & Me![cboFind].column(1) & "'"

column() is a zero-based index into the combobox's columns.
If [First name] is not the second column, adjust accordingly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top