dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Searching a database with ADO control Find feature

  1. #1
    Danielsova Guest

    Searching a database with ADO control Find feature


    Hi,

    I'm trying to figure out how to use the Find feature with the ADO control.
    I'm using the "Biblio" database that comes with VB. I've tried everything
    on Microsoft's site and others, and I'm really getting desperate for the
    answer! With the code that I have now, the results of the search always
    come back as "No Matching Records," even if there should be at least one.
    I'm using text boxes to display the information from two of the tables in
    the database. Any help would be greatly appreciated! Here is the code I
    have so far:

    Private Sub mnuAuthor_Click()

    'provide method of searching for Author Information

    Dim oCn As New ADODB.Connection
    Dim rst As New ADODB.Recordset


    ' Set the recordset
    Set rst = Adodc1.Recordset

    ' Provide input box to enter the name of the author to search
    SearchQuery = InputBox("Enter the name of the Author", "Author Search")

    ' Open the connection
    oCn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=C:\My Documents\Biblio23.mdb"

    ' Find the Author named in the input box
    rst.Find "Author = 'SearchQuery'", 1, adSearchForward

    'If there are no matching files by EOF then display messagebox and then
    move to the first record
    If rst.EOF Then
    MsgBox "No Matching Records Found", vbOKOnly
    rst.MoveFirst
    End If

    End Sub






  2. #2
    huibert Guest

    Re: Searching a database with ADO control Find feature


    "Danielsova" <kmilata@briefcase.com> wrote:
    >
    >Hi,
    >
    >I'm trying to figure out how to use the Find feature with the ADO control.
    > I'm using the "Biblio" database that comes with VB. I've tried everything
    >on Microsoft's site and others, and I'm really getting desperate for the
    >answer! With the code that I have now, the results of the search always
    >come back as "No Matching Records," even if there should be at least one.
    > I'm using text boxes to display the information from two of the tables

    in
    >the database. Any help would be greatly appreciated! Here is the code

    I
    >have so far:
    >
    >Private Sub mnuAuthor_Click()
    >
    >'provide method of searching for Author Information
    >
    >Dim oCn As New ADODB.Connection
    >Dim rst As New ADODB.Recordset
    >
    >
    >' Set the recordset
    > Set rst = Adodc1.Recordset
    >
    >' Provide input box to enter the name of the author to search
    > SearchQuery = InputBox("Enter the name of the Author", "Author Search")
    >
    >' Open the connection
    > oCn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=C:\My Documents\Biblio23.mdb"
    >
    >' Find the Author named in the input box
    > rst.Find "Author = 'SearchQuery'", 1, adSearchForward
    >
    >'If there are no matching files by EOF then display messagebox and then


    > move to the first record
    > If rst.EOF Then
    > MsgBox "No Matching Records Found", vbOKOnly
    > rst.MoveFirst
    > End If
    >
    >End Sub
    >
    >


    1) try to figure the difference between
    rst.Find "Author = 'SearchQuery'", 1, adSearchForward
    and
    rst.Find "Author = '" & SearchQuery & "'", 1, adSearchForward

    2) How is ADO supposed to know what table to query???? I think you need to

    do an rs.open "SELECT * FROM Authors". The find method will then search the
    Recordset for an author you have named.

    hth
    huibert

  3. #3
    Danielsova Guest

    Re: Searching a database with ADO control Find feature


    "huibert" <hvandeursen@wanadoo.nl> wrote:
    >
    >"Danielsova" <kmilata@briefcase.com> wrote:
    >>
    >>Hi,
    >>
    >>I'm trying to figure out how to use the Find feature with the ADO control.
    >> I'm using the "Biblio" database that comes with VB. I've tried everything
    >>on Microsoft's site and others, and I'm really getting desperate for the
    >>answer! With the code that I have now, the results of the search always
    >>come back as "No Matching Records," even if there should be at least one.
    >> I'm using text boxes to display the information from two of the tables

    >in
    >>the database. Any help would be greatly appreciated! Here is the code

    >I
    >>have so far:
    >>
    >>Private Sub mnuAuthor_Click()
    >>
    >>'provide method of searching for Author Information
    >>
    >>Dim oCn As New ADODB.Connection
    >>Dim rst As New ADODB.Recordset
    >>
    >>
    >>' Set the recordset
    >> Set rst = Adodc1.Recordset
    >>
    >>' Provide input box to enter the name of the author to search
    >> SearchQuery = InputBox("Enter the name of the Author", "Author Search")
    >>
    >>' Open the connection
    >> oCn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=C:\My Documents\Biblio23.mdb"
    >>
    >>' Find the Author named in the input box
    >> rst.Find "Author = 'SearchQuery'", 1, adSearchForward
    >>
    >>'If there are no matching files by EOF then display messagebox and then

    >
    >> move to the first record
    >> If rst.EOF Then
    >> MsgBox "No Matching Records Found", vbOKOnly
    >> rst.MoveFirst
    >> End If
    >>
    >>End Sub
    >>
    >>

    >
    >1) try to figure the difference between
    >rst.Find "Author = 'SearchQuery'", 1, adSearchForward
    >and
    >rst.Find "Author = '" & SearchQuery & "'", 1, adSearchForward
    >
    >2) How is ADO supposed to know what table to query???? I think you need

    to
    >
    >do an rs.open "SELECT * FROM Authors". The find method will then search

    the
    >Recordset for an author you have named.
    >
    >hth
    >huibert



    huibert,

    THANKS!!!!

    All I had to do was use the Find statement that you suggested replacing my
    original one with, and it works! I didn't have to use the SQL statement,
    but when I tried, I kept getting an object error.

    Anyway, thanks so much again!

    Danielsova


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center