Question : Microsoft, Access, 2003, VBA, Make a record found in a recordset the current record of a form

I'm teaching myself how to use recordsets

A form, frmRecordset has a single command button, cmdRecordset, and a text field, txtName
This form uses a table, tblProspect, as its Record Source.

tblProspect has three fields:
   hPhone, a double precision number storing 10-digit phone numbers
   NameF, a string storing prospective client's first names
   NameL, a string storing prospective clinet's last names

cmdRecordset successfully bookmarks tblProspects recordset for the matching phone number find (see code).  
By filtering the form's source with code (as shown) the form displays data from the seek in txtName (=[NameF] & " " & [NameL] & " at, " & format([hPhone], "(000) 000-0000"), but the form is now limiited to a single record.  This is fine for some things.
How can I make the frmProspect's current record the same as the matched recordset record, so that, after examining the found record, all other records are present for frmProspect to navigate through.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
Option Compare Database
Option Explicit
 
Private Sub cmdRecordset_Click()
Dim dbs As DAO.Database
Dim rsTable As DAO.Recordset
Dim dblPhone As Double
 
Set dbs = CurrentDb
Set rsTable = dbs.OpenRecordset("tblProspect", dbOpenTable)
 
dblPhone = 4134980210#
rsTable.Index = "PrimaryKey"
rsTable.Seek "=", dblPhone
 
If rsTable.NoMatch = True Then
    MsgBox "Did not find"
Else
    Me.Filter = "[hPhone] = " & rsTable!hPhone
    Me.FilterOn = True
End If
 
Set rsTable = Nothing
End Sub
Open in New Window Select All

Answer : Microsoft, Access, 2003, VBA, Make a record found in a recordset the current record of a form

The simplest way is to use the RecordsetClone of your form:

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.Find [hPhone] = " & rsTable!hPhone

If Not rs.NoMatch Then
  Me.Bookmark = rs.Bookmark
End If

Why did you set the Datatype of your phone number field to Numeric? Phone numbers are almost always stored as Text, since you have no need to perform any calculations on them, and with a Text data type you can handle many different types of numbers.
Random Solutions  
 
programming4us programming4us