Hi
I have created a database using ms access linked with vb6.But i am having difficulty coding or programming for
a method that will help me find and retrieve a specific record.Any time i try, it either tell s me a runtime error has occurred or data member not defined.In any case, i don't even know what "data member not defined"means.
I need help on how to solve this problem.Thank you.

Recommended Answers

All 3 Replies

Hi,
The field name you supplied with may be wring spelled or not exist the recordset you created...

you are trying to use an undeclered search string.

try the following code. before u try to run it create an access db(employee.mdb) under the same folder as ur project exists. in the db create a table(details) with three fields(id,name,basic). in the form take the following objects :-(see the interface screenshot)

Option Explicit

Dim db As Database
Dim rs As Recordset

Private Sub cmdsearch_Click()
If Trim(txtsearch.Text) <> "" Then
    Set rs = db.OpenRecordset("select * from details where id='" & Trim(txtsearch.Text) & "'")
    If rs.RecordCount > 0 Then
        txtid.Text = rs!id
        txtname.Text = rs!Name
        txtbasic.Text = rs!basic
        txtsearch.SelStart = 0
        txtsearch.SelLength = Len(Trim(txtsearch.Text))
        txtsearch.SetFocus
    Else
        MsgBox "Sorry, there is no such record found in the database with Employee ID :" & _
            Trim(txtsearch.Text) & "." & vbCrLf & "Please try again...", vbExclamation, "Employee"
        txtid.Text = ""
        txtname.Text = ""
        txtbasic.Text = ""
        txtsearch.SelStart = 0
        txtsearch.SelLength = Len(Trim(txtsearch.Text))
        txtsearch.SetFocus
    End If
Else
    MsgBox "Please mention the employee id to search for.", vbExclamation, "Employee"
    txtsearch.SetFocus
End If
End Sub

Private Sub Form_Load()
Set db = OpenDatabase(App.Path & "\employee.mdb")
Set rs = db.OpenRecordset("details", dbOpenTable)

If rs.RecordCount > 0 Then
    rs.MoveFirst
Else
    MsgBox "Please add some records to the database before you try to search.", vbInformation, "Employee"
End If
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.