Results 1 to 7 of 7
  1. #1
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47

    FindFirst error

    The code below generates the error "Runtime error 3251. Operation is not supported for this object type" on the line


    rst.FindFirst "[Costume Number] = '205-001'"

    I am new to Access and must be doing something dumb but I cannot find what I am doing wrong. Help will be appreciated. Thanks.

    Private Sub Show_Costume_Description()


    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset

    'Get the Costume table recordset.
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("Costume")


    'Find the Costume record for the current Checkout
    'table record.
    rst.FindFirst "[Costume Number] = '205-001'"

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    dont use FINDFIRST.
    Just filter the records in the search in the form. Then there's nothing to find, they ALL match.

    'me.filter = "[state]='NY'"
    me.filter = "[state]='" & cboStates & "'"
    me.filterOn = true

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Costume Number in the table is a text field?

  4. #4
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    Found the problem. If I open the recordset as a dynaset FindFirst works. Costume Number is a text field and it is the primary key so I only need to call FindFirst to get the unique record. Thanks.

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    What's the syntax for your solution? I suspect Set rst = dbs.OpenRecordset("Costume",1) since (I think) the default is dynaset but of type 0, which requires the records to be based on a single table or tables with one to one relationships. BTW, there is no guarantee that when you open a recordset that you will start at what you think is the beginning. I would .MoveFirst before using FindFirst.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    If I recall correctly, a DAO recordset will point to the first record after openrecordset even without the rs.moveFirst--if there is a least 1 record in the recordset.

    You can test for this condition using
    if rs.recordcount =0 then......'empty recordset
    and if some records exist, the .movefirst is redundant

    However, many people use it (moveFirst), probably because of the following:

    DAO loads some records on the Openrecordset, but not all records.

    If you want a true recordcount for the recordset, you need to do a rs.MoveLast to get to the Last record and the real count;
    then do a rs.moveFirst to get back to the beginning on the recordset for Loop or other processing.

    I have not found an m$oft reference, but I seem to recall learning that way back when...
    Last edited by orange; 03-01-2017 at 09:32 AM. Reason: spelling

  7. #7
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    You are correct. From MS:
    When you create a Recordset object, the current record is positioned to the first record if there are any records. If there are no records, the RecordCount property setting is 0, and the BOF and EOF property settings are True.
    If you want the page, it is here https://msdn.microsoft.com/en-us/lib.../ff197799.aspx
    Interesting info there about how undeclared rs types are handled. Seems you're taking your chances if you don't declare the type.
    Thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Syntax Error in FindFirst 1/2 of the time
    By timesscript in forum Programming
    Replies: 3
    Last Post: 07-09-2015, 02:22 PM
  2. .findFirst 3077 syntax error
    By RonL in forum Programming
    Replies: 3
    Last Post: 04-05-2015, 04:22 PM
  3. .FindFirst problem
    By akhmadahdiyat in forum Programming
    Replies: 2
    Last Post: 11-29-2013, 12:27 AM
  4. Using FindFirst code
    By saltydawg617 in forum Access
    Replies: 2
    Last Post: 07-29-2011, 05:21 PM
  5. using FindFirst with a Date Criteria (syntax error)
    By ajetrumpet in forum Programming
    Replies: 2
    Last Post: 09-10-2010, 11:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums