I need help to write the code to filter a Recordset called Data1 and a Field called AWEIGHT, when loading a form. I tried the following and it does not work. After the form is opened I only want to be able to search the filtered records. An example would be nice.

Private Sub Form_Load()
Data1.Recordset.Filter = "AWEIGHT > 0"

End Sub

Recommended Answers

All 2 Replies

Well reading the help file on this it says that for better performance that you should use a query with a where clause...

so...

strSQL = "SELECT * FROM SomeTable WHERE SomeField = somevalue
Set Rs = Db.OpenRecordset(strSQL,...

Good Luck

I solved my problem by doing the following instead of using a filter.

Private Sub Form_Activate()
Data1.Recordset.MoveLast

If txtWeight > 0 Then
GoTo 2
End If
1
If txtWeight = 0 Then
Data1.Recordset.MovePrevious
GoTo 1
End If
Call Show
2
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.