Results 1 to 6 of 6
  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: Method or data member not found

    The error appeared in .FindFirst method in my code.
    My code is quite straight forward. Can you see why it does not work?

    Private Sub cmdSearch_Click()

    Dim db As Database
    Dim rst As Recordset
    Dim strSearch As Variant


    Set db = CurrentDb()
    Set rst = db.OpenRecordset("tblPurchase")
    strSearch = Me!txtSearchValue
    'A variable stores the value of the textbox that is to be searched.

    With rst
    .MoveLast
    .FindFirst strSearch Error: “Method or data member not found (Error 461)” and FindFirst is highlighted

    If .NoMatch Then
    MsgBox "Record not found"
    End If

    End With
    rst.Close

    db.Close

    Exit_cmdSearch_Click:
    Exit Sub

    Err_cmdSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdSearch_Click

    End Sub


    Thanks!

  2. #2
    Join Date
    Nov 2001
    Posts
    336
    Hi,

    Change strSearch = Me!txtSearchValue expression to something like:

    strSearch = "MyNumericField=" & Me!txtSearchValue

    You can also consider using DLookup() function as a replacement of your the whole code. Search MS Access help for examples on using this function.

    Igor

  3. #3
    Join Date
    May 2002
    Posts
    395

    Search all fields

    Hi Igor,


    Thanks for your help on the code.
    strSearch = "MyNumericField=" & Me!txtSearchValue
    Does "MyNumericField=" means I can search this field only?


    Also you suggested the DLookup Function. Could I use DLookup to search all the fields in a table that matches the input value entered in a textbox? The value to be searched may be in any of the fields in the table, I need a method to search each field and return all of the records with the matching criteria.

    Could you help?
    Thank you.

  4. #4
    Join Date
    Nov 2001
    Posts
    336
    You wrote:
    strSearch = "MyNumericField=" & Me!txtSearchValue
    Does "MyNumericField=" means I can search this field only?

    You can extend your search like here:
    strSearch = "MyNumericField=" & Me!txtSearchValue & " And MyName='" & me.txtSearchName & "'"

    You wrote:
    Could I use DLookup to search all the fields in a table that matches the input value entered in a textbox?

    Of course you can.

    You wrote:
    I need a method to search each field and return all of the records with the matching criteria

    It looks like the output in this case should be a recordset. Not Found or NotFound value or Count of recods matching the criteria.
    My best bet would be to write a query to return the recordset of matching records.

    Igor

  5. #5
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    147
    alicjwz,

    FindFirst is a method of DAO, and not ADO, meaning that you need to have a reference to that DAO library.

    The error message you receved is usually due to not having a reference set to that library, or the ADO library being referenced before the DAO one.

    Firstly make sure you have a reference set to the latest DAO object library "Microsoft DAO x.x Library" x.x should be around 3.6 (Tools -> References).

    Secondly, to avoid the ordering problem, make sure you reference that particular library in your code. So:

    Code:
    Dim db As Database 
    Dim rst As Recordset
    should be
    Code:
    Dim db As DAO.Database 
    Dim rst As DAO.Recordset
    Also, you've gone rst.movelast before doing a search. Shouldn't this be movefirst?

    Hope this helps.

    Cheers,
    Andrew
    Last edited by Bunce; 07-10-02 at 06:41.
    There have been many posts made throughout the world.
    This was one of them.

  6. #6
    Join Date
    May 2002
    Posts
    395

    Method or data member not found

    Hi Andrew,

    That’s exactly what happened, the ADO library was being referenced before the DAO.
    Thanks for your help!

    With rst
    .MoveLast

    I was trying to populate the recordset, I am not sure it’s going to work.

    Thanks again.

Posting Permissions

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