Results 1 to 11 of 11

Thread: Using ADO recordset Find method

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    55
    Hi VB gurus

    How can i use Find method of Recordset object in ADO.
    I can do that through DAO using FindFirst,FindNext,FindLast and FindPrevious methods.
    These methods are not there in ADO.
    Please help me

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84

    Arrow

    try using something like this:

    Code:
       Dim SearchNumber as Integer
       Dim SearchString as String
    
       With Recordset
          .MoveFirst
    
          'if you're searching for a number
          .Find "ColumnName=#" & SearchNumber & "#"
    
          'or for a string:
          '.Find "ColumnName=' & SearchString & "'"
    
          If Not .EOF Then
    
             'a record was found
             'do something
    
          End If
       End With
    hope this helps!

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    55

    Red face

    ThanQ Nina

    What you specified is for simple searching.

    suppose i am having a table Orders. which contains a field Customer_name.In that field there is the repetetion of each customer name since one customer can place many orders.
    Now i want searh for records based on aparticular customer name. According to you i will move to the first record and
    execute
    rs.find customer_name='xxxxx'.

    The record pointer moves to the first existance of the customername.
    now i want to move to the second existance of the same customer.(in DAO i can achieve this using
    rs.findnext cust_name='xxxxx')
    how can i do this using ADO.

    also if the record pointer is at third existance of the customer_name 'xxxxx'.Now i want to move to the second existance.(Using DAO i can do this using
    Rs.FindPrevious customer_name='xxxxx')
    How can i do this Usin ADO.

    Please find the solution for this
    Thanks in advance.


  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Filter or SQL

    If you use
    ADO.recordset.Filter="CustomerName LIKE '" & varCusName & "'"
    it will return all the records that met the criteria if you need more criteris just use AND in it. varCusName would just be a variable or control with the string of what to search for.
    Or change the recordset to be a SQL statement
    Set Recordset="Select * From CustomerOrders WHERE CustomerName=". ... yada yada
    Read the help topics for Filter and SQL and see if it is what you are looking for.

  5. #5
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    If you want to get several records as a result I would create a new recordset with just these records ...
    I think that's the easiest way ...

    e.g.
    StrSQL = "SELECT * FROM Table WHERE Customer_Name=" & SearchString


  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    55

    Red face

    That's OK.
    You are all sugesting alternatives.
    But There comes a situation where you have to scroll through the recordset that contains all the record inthe table.
    I don't want to fire a recordset for each criteria every time.

    Please find the solution for my problem( No alternatives please).

  7. #7
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    Well, if you want to go through all records in a recordset you can use

    movefirst
    movelast
    movenext
    moveprevious

    is that what you are looking for?

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    55
    No Nina

    You know FindFirst,FindNext, FindPrevious, FindLast in DAO. Right?
    I want the Equivalents in ADO.

    Now tell me the solution

  9. #9
    Member
    Join Date
    Sep 2000
    Location
    Kentucky
    Posts
    56
    I think what you want to do is possible in ADO and pretty simple.

    VB Code:
    1. FindFirst:
    2. rs.MoveFirst
    3. rs.Find Criteria, 0, adSearchForward
    4.  
    5. FindNext:
    6. rs.Find Criteria, 1, adSearchForward  ' The 1 tells it to skip the current record.
    7.  
    8. FindPrevious:
    9. rs.Find Criteria, 1, adSearchBackward
    10.  
    11. FindLast:
    12. rs.MoveLast
    13. rs.Find Criteria, 0, adSearchBackward

    Look at the MSDN article on Find Method (ADO), but in the syntax section ignore the parentheses.

    I haven't used this much, but I think it will work for you.

  10. #10
    Lively Member Wally Pipp's Avatar
    Join Date
    Jan 2002
    Location
    Carnivàle
    Posts
    79
    can't you use the .index and .seek methods ?

    set the index first and then seek with parameters.

    Or filter the results out as stated above.
    A post brought to you by the Grim Reaper Appreciation Society™

    "Buy your lifetime subscription now and save on your coffin"

  11. #11
    Member
    Join Date
    Sep 2000
    Location
    Kentucky
    Posts
    56
    .index and .seek are DAO Methods not ADO.

    You could use .Filter then use the .MoveFirst, .MoveNext, .MovePrevious, .MoveLast to move around in the records that are selected.

    I prefer to use .Find if I am looking for 1 record and searching only one field. For anything complicated .Filter works better.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width