recall a record

shagha

Registered User.
Local time
Yesterday, 23:31
Joined
Jun 19, 2013
Messages
14
I want to recall a record by it's primary key in a form with a command button

I mean write a primary key in a textbox and press the button then it shows the record.
 
Assuming that the form shows all the records in your your table and you want to jump to the chosen record, and that the Primary Key is a number ...

Code:
Private Sub yourCommandButton_Click()
With Me.RecordSetClone
  .FindFirst "yourPrimaryKey = " & val(me.yourTextBox & vbNullString)
  If .NoMatch Then
    MsgBox "Record not found", vbInformation + vbOkOnly
  Else
    Me.Bookmark = .Bookmark
  Endif

End With
End Sub
 
Last edited:
thanks for the code

but my form doesn't show any record at first, I want it to show just the specific record that i call.
 
I prefer to use criteria in my form's RecordSource query. This allows me to use the same technique whether my BE is Jet/ACE or SQL Server/Oracle/DB2/etc.

Change the query to include criteria:
Select ...
From ...
Where MyField = Forms!frmMyForm!txtMySearchField;

Then in the AfterUpdate event of the text box, you need to requery the form.

Me.Requery

Limiting the bound recordset to the minimum number of records is good practice for client server applications since it minimizes network traffic. It does prevent you from using .FindFirst or Filter though.
 

Users who are viewing this thread

Back
Top Bottom