0

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

2
Contributors
1
Reply
3
Views
10 Years
Discussion Span
Last Post by choudhuryshouvi
0
'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

Edited by happygeek: fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.