Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset filter 1

Status
Not open for further replies.

tommeekers

Programmer
Sep 10, 2003
77
0
0
BE
I have a very weird problem with filtering a recordset.
The code below is triggered when I press a button. It first runs a query which creates the table temp and then I want to step through each record which meets the criteria in that table using a recordset filter.

Code:
Set db = CurrentDb()
Set rs = db.openrecordset("temp")
[highlight]rs.Filter = "[field1] = True"[/highlight]
Set rs = rs.openrecordset
rs.MoveFirst
Do While Not rs.EOF
     [COLOR=green]'
     '
     '[/color]
     rs.MoveNext
Loop

It keeps returning an error at the highlighted line. I've used this code before in my application and it works fine, except in this case.

[tt]Error 3251 Operation is not supported for this type of object[/tt]
 
What type of field is [field1] in your recordset?

Have you tried rs.Filter = "[field1] = -1" ?
 
Note When you know the data you want to select, it's usually more efficient to create a Recordset with an SQL statement. This example shows how you can create just one Recordset and obtain records from a particular country.

Sub FilterX2()

Dim dbsNorthwind As Database
Dim rstOrders As Recordset

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

' Open a Recordset object that selects records from a
' table based on the shipping country.
Set rstOrders = _
dbsNorthwind.OpenRecordset("SELECT * " & _
"FROM Orders WHERE ShipCountry = 'USA'", _
dbOpenSnapshot)

rstOrders.Close
dbsNorthwind.Close

End Sub
 
Ok, that solved the problem.
I just limited my recordset to the records I need by using an SQL statement. So there is no need to use a filter anymore.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top