Avatar of dsoderstrom
dsoderstrom
 asked on

Problem with DAO FindFirst

I'm getting an error message on the FindFirst line in the following code.
The error message is "Run-time error '3251'   Operation is not supported for this type of object."
Can someone tell me what I am doing wrong?

    Dim rs As DAO.Recordset
    Dim rs2 As DAO.Recordset
    Dim i As Long
    Dim reccount As Long
   

    Set rs = CurrentDb.OpenRecordset("2015and2016ServicePartsOrders")
    Set rs2 = CurrentDb.OpenRecordset("ItemPriceHistory")
    reccount = DCount("*", "2015and2016ServicePartsOrders")
    rs.MoveFirst
    For i = 1 To reccount
        rs2.FindFirst ("[ItemNumber]= ' " & rs!ItemNumber & " ' ")
        If rs2.NoMatch Then
            rs.Edit
            rs![List Price] = 0
            rs.Update
        Endif
        If i = reccount Then
            Exit For
        Else
           rs.MoveNext
        End If
  next I
  rs.close
  rs2.close
Microsoft Access

Avatar of undefined
Last Comment
dsoderstrom

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bill Prew

I also notice you have extra spaces, please adjust this line as well so the matches will be found:

        rs2.FindFirst ("[ItemNumber] = '" & rs!ItemNumber & "' ")

Open in new window


»bp
Jim Dettman (EE MVE)

    Dim db as DAO.Database
    Dim rs As DAO.Recordset
    Dim rs2 As DAO.Recordset

   Set db = CurrentDB()
    Set rs = db.OpenRecordset("2015and2016ServicePartsOrders")
    Set rs2 = db.OpenRecordset("ItemPriceHistory")

   Do until rs.EOF
        rs2.FindFirst  "[ItemNumber]= ' " & rs!ItemNumber & " ' "
        If rs2.NoMatch Then
            rs.Edit
            rs![List Price] = 0
            rs.Update
        Endif

        rs.MoveNext
   loop

  rs.close
  Set rs = nothing

  rs2.close
  set rs2 = nothing

  set db = nothing

Open in new window

dsoderstrom

ASKER
That fixed the problem.  Thank You.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23