Primary Key - moving through database

T

thisun

I have built a database using social security # as the primary key. Is there
a way for me to simply enter the ss # of an existing record to go to that
record ? I am using Access 2003.
 
A

Allen Browne

You probably know that you can click in the ss# field, and use the Find
button on the Toolbar (binocular icon).

In a form, you could add an unbound text box where the user enters the
number to find. Typically this goes into the Form Header section, and has a
different BackColor to distinguish it from the bound controls. Use its
AfterUpdate event procedure to find the record, so the user just has to
enter the value and press Enter.

Private Sub txtGoto_AfterUpdate()
Dim strWhere As String

If Not IsNull(Me.txtGoto) Then
If Me.Dirty Then 'Save before move.
Me.Dirty = False
End If

strWhere = "[ss#] = """ & Me.txtGoto & """"
With Me.RecordsetClone
.FindFirst strWhere
If .NoMatch Then
MsgBox "Not found"
Else
Me.Bookmark = .Bookmark
End If
End With
End If
End Sub


Notes:
1. Have assumed your field is of type Text. If it is number, drop the extra
quotes, i.e.:
strWhere = "[ss#] = " & Me.txtGoto
2. If the form is filtered, a valid number may not be found.
 

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