anybody know the coding for searching by primary key?

example:
i have database name "FAIL",
table name "Fail"
and i want to search by field name " Nama Fail"

i really need the help to finish my project

'used stuffs : textbox(txtname); command button(command1)

Option Explicit
Dim db As Database, rs As Recordset

Private Sub Command1_Click()
If Trim(txtname.Text) <> "" Then
    Set rs = db.OpenRecordset("select *from fail where nama_fail=" & Chr(34) & Trim(txtname.Text) & Chr(34))
    If rs.RecordCount > 0 Then
        MsgBox "The name is found."
    ElseIf rs.RecordCount = 0 Then
        MsgBox "The name is not found in the collection."
    End If
    SendKeys "{Home}+{End}"
    txtname.SetFocus
    Set rs = Nothing
Else
    MsgBox "Please enter name first to begin searching."
    txtname.SetFocus
End If
End Sub

Private Sub Form_Load()
Set db = OpenDatabase(App.Path & "\fail.mdb")
Set rs = db.OpenRecordset("fail", dbOpenTable)
If rs.RecordCount > 0 Then rs.MoveFirst
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.