Hi all,
i am doing my project. i need one search box to find something i write in the box, how can i code that?
its very important please help

Dani AI

Generated

A few practical points that fill the gap between the earlier advice and the working line you posted: there are two common, simple approaches for a “type-and-search” box in VB6 + ADO — move the existing Recordset to the matching row (what you discovered), or issue a focused SQL query and read the result into the target textbox. For small, already-open Recordsets the find/filter route is fine; for larger tables a SELECT with a WHERE is more reliable and usually faster.

A minimal, safe pattern that works on a button click (change table/field names and the Connection string to suit your DB):

Private Sub cmdSearch_Click()
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sql As String
    Dim term As String

    term = Trim(txtSearch.Text)
    term = Replace(term, "'", "''")    ' escape single quotes

    sql = "SELECT TOP 1 OtherField FROM MyTable WHERE [Name] LIKE '%" & term & "%'"

    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Path\YourDB.mdb;"  ' adjust

    Set rs = New ADODB.Recordset
    rs.Open sql, cn, adOpenForwardOnly, adLockReadOnly

    If Not rs.EOF Then
        txtResult.Text = Nz(rs.Fields("OtherField").Value, "")
    Else
        txtResult.Text = ""
    End If

    rs.Close: cn.Close
    Set rs = Nothing: Set cn = Nothing
End Sub

Notes and troubleshooting

  • Use TOP 1 when you only need a single match.
  • Prefer ADODB.Command with parameters for true parameterization where supported (avoids concatenation).
  • If the textbox is data‑bound, moving the record pointer will update controls automatically; otherwise set the destination textbox explicitly.
  • Escape quotes, check for Nulls, and ensure the search column is indexed if performance is an issue.
  • In VB6 make sure the Microsoft ActiveX Data Objects reference is set and field names with spaces/reserved words are bracketed.

This complements ’s Recordset approach and the ADO setup reminders from by giving a concrete, robust example and practical tips for everyday problems (empty results, quoting, performance).

Recommended Answers

All 7 Replies

Hi

What have you tried so far? Where is your attempt?

To give you a start, check out How to Open ADO Connection and Recordset, this will show you how to connect to a database using ADO and how to open a recordset which will contain records from the database based on a query. It isn't a complete tutorial as it is missing some pieces such as moving through the recordset, but it will get you going. Then post back the code that you have tried and we will be able to help you further.

HTH

thanks i advance for the answer
i have linked a database with ado now how can i get a record from a field in a table? via box or via combo? and how? my db has tables and they have feilds, now i want to enter a record to the box and it show me the result how?

What code do you have so far that demonstrates what you are tyring to achieve?

i don't know exactly what to do i will upload you a picture this picture i have linked the textbox to a datafild, now when i want to click on serach it should show me the result in the next textbox.

Hi

Maybe you could check out this tutorial: Visual Basic and ADO Tutorial. I don't have access to VB6 so cannot provide a decent example, but hopefully the linked tutorial will give you a good start.

HTH

Ok thanks alot

i figured it out and found the solotion like this:
'Adodcdsearch.Recordset.Find "[Name]='" & txtdsearch.Text & "'"
this was the code i was searching for.
thank you guys.

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.