Code Modification

G

Guest

Hello All,

I have a Combo box that looks up values in the Last Name field. It works
fine but it only BookMarks the first occurance of any matching criterior. My
Combo box has two columns "Last Name", "First Name". What I would like to do
is modify the code to force it to bookmark criterior based on both fields if
that's possible.

Here's the code for the Combo box:


Option Compare Database
Option Explicit
Const adhcQuote = """"

Private Sub cboFindLast_AfterUpdate()

Dim rst As DAO.Recordset

Set rst = Me.RecordsetClone

rst.FindFirst "[Last Name] = " & _
adhHandleQuotes(Me!cboFindLast, adhcQuote)

If rst.NoMatch Then
MsgBox "No match was found."
Else
Me.Bookmark = rst.Bookmark
End If

Set rst = Nothing
End Sub
 
M

Mark

Does your names table have a primary key field? If not, you should add one;
for the purpose of looking up records, an autonumber would work fine as a
primary key. Your combo box's row source should include this field (and be
bound to it). You can hide this column so your users only see the lastname
and firstname. Then when you do your search, you only need to look for an
integer value and you won't have to worry about any quotes in the search
string. Since you'd be matching a primary key value, you will be assured of
matching the exact record that was selected in the combo box.
 

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