"Deac" <
mwa...@centurylink.net> wrote in message
news:cf775a6c-d507-4946...@t2g2000yqk.googlegroups.com...
Typically you'd just use two combo boxes - one for searching by name, and
the other for searching by ID. They both can have ID as the bound column in
the combo box, so you can use the same code for both - find based on ID. The
only difference would be what the user would see. In the name search, the ID
column (first column) would be hidden, and they'd only see the name. But the
combo box VALUE would still be the ID. And in the ID search, the ID column
would not be hidden, and there would be two columns (ID and name). But the
ID would still be the combo box value.
If you want to use one combo box for both, it would be a bit tricky, since
you'd have to make the combo box not be limited to the list (and you
wouldn't be able to use a hidden column). So if you want to do that you can.
You'd use IsNumeric to determine if the user entered a number or a name.
Also, your code above will not work with If Not rs.EOF (or, rather, it will
always set Me.Bookmark to rs.Bookmark, rather than only if there's a match).
If FindFirst doesn't find a match, it's not going to move past the end of
the recordset. It's just not going to move at all, if it doesn't find a
matching record. So the recordset cursor will remain where it is, not at
EOF.
What you want to use instead is the NoMatch property of the recordset. That
will tell you whether there's a match or not. So:
Set rs = Me.Recordset.Clone
rs.FindFirst "[IDold] = '" & Me![ContactSelection] & "'"
If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark
To have it work with either name or ID entries:
Set rs = Me.Recordset.Clone
If IsNumeric(Me![ContactSelection]) then
rs.FindFirst "[ID] = " & Me![ContactSelection]
Else
rs.FindFirst "[IDold] = '" & Me![ContactSelection] & "'"
End If
If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark
(I'm assuming in the above that [ID] is the numeric ID, and [IDold] is the
name. But you should change the field names to whatever they actually are.)
HTH,
Neil