FindFirst Error 3251

grahamvb

Registered User.
Local time
Today, 07:35
Joined
Aug 27, 2013
Messages
57
This is generating error 3251. What is amiss here?
Thanks for looking at this.

Code:
Private Sub btn_Click()
 
Dim db As DAO.Database
Dim rstTable As DAO.Recordset
Dim VarID As Integer
Dim varString As String
Dim varString2 As String
 
Set db = CurrentDB
Set rstTable = db.OpenRecordset("tblTable")
 
 varID = 1
 
 varString = "[Field1] = " & varID 
 rstTable.FindFirst varString ' [COLOR=red]Error 3251, Operation is not supported for this type of object.[/COLOR]
 varString2 = rstTable.Fields("Field2")
 
 Debug.Print varString & ", " & varString2
 
End Sub
 
Don't open a huge recordset and wade through it. Rather, you'll get way better performance and reliability if you open exactly the recordset you need. Consider . . .
Code:
    Dim rst As DAO.Recordset
    Set rst = CurrentDb.OpenRecordset( _
        "SELECT Field2 " & _
        "FROM tblTable " & _
        "WHERE Field1 = 1")
    
    With rst
        If Not .EOF Then
            Debug.Print 1 & ", " & .Fields(0)
        Else
            Debug.Print "Not Found"
        End If
        .Close
    End With
See how this code applies a WHERE clause to the SQL that is used to open the recordset? Then we check if a record was found or not.
 

Users who are viewing this thread

Back
Top Bottom