Forum Discussion

Maxine14062's avatar
Maxine14062
Brass Contributor
Oct 15, 2024

FindFirst not working

I have a 365 database with the following code:

Set rst = CurrentDb().OpenRecordset("SchedFieldTable")

mFID = DLookup("[FID]", "SchedFieldTable", "[Width]+[Left] > 10.5 * 1440")
MsgBox "[FID] = " & mFID
rst.FindFirst "[FID]= " & mFID 

where FID, Width, and Left are all number fields in the table SchedFieldTable. The message box result is: [FID]=25, which is correct.

I get an error on the line:

rst.FindFirst "[FID]= " & mFID

I have also tried: rst.FindFirst "[FID]= '" & mFID & "'"

Can you help? This is driving me nuts!!!

 

  • George_Hepworth's avatar
    George_Hepworth
    Silver Contributor
    Please explain the logic you are trying to implement here. It looks like you are trying to add two values and compare them to 10.5 * 1440, but I don't understand why you would do that.

    Also, when reporting problems, it's better to include the exact error and error description, not just mention "an error". The error descriptions help us figure out what to look for.

    "[Width]+[Left] > 10.5 * 1440"
    • Maxine14062's avatar
      Maxine14062
      Brass Contributor
      My table has fields to locate controls on a report. The Width and Left fields will be used to position the controls on a 10.5" wide report. If a lot of fields are selected for inclusion on the report, some will have to be moved down to a lower position. That is why I am testing for "[Width]+[Left]> 10.5*1440". The error is: 3251 Operation is not supported to this type of object. Can you help?
      • George_Hepworth's avatar
        George_Hepworth
        Silver Contributor

        Maxine14062 

        Okay, that objective makes sense.  

         

        This procedure, though, doesn't.

         

        Can you provide some sample data from the table to help me visualize what's going on?

  • arnel_gp's avatar
    arnel_gp
    Steel Contributor

    Maxine14062 , maybe set your recordset like this:

     

    Set rst = CurrentDb.OpenRecordset("SchedFieldTable", dbOpenDynaset)

  • Maxine14062 

    You can filter the recordset directly:

        Dim rst As DAO.Recordset
        Dim SQL As String
    
        SQL = "Select * From SchedFieldTable Where [Width] + [Left] > 10.5 * 1440"
        Set rst = CurrentDb.OpenRecordset(SQL)
        
        If rst.RecordCount > 0 Then
            ' List the found FIDs.
            rst.MoveFirst
            While Not rst.EOF
                Debug.Print rst!FID.Value, rst!Width.Value, rst!Left.Value
                rst.MoveNext
            Wend
        End If
        rst.Close
    • Maxine14062's avatar
      Maxine14062
      Brass Contributor
      Thanks all of you. But I got it to work by myself.

Resources