Discussion Locked

Filtering w/o using a query from an "RS"

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I had a recordset with a query select * from emp
I filtered it with rs.filter "Sal>" & varSal as i don't want to use "query" for filtering.
Then I filtered again with rs.filter
"Job='" & varjob & "'". The problem is - it's filtering the actual recordset rather than the sal filtered records. I want to give 2 conditions "sal> and job=" but vb is not accepting 2 conditions with filter. How can i filter with 2 conditions w/o(without) using a query but using a "filter" method of the recordset object

3 replies

by timfox

Are you using this in Access?

If so, you should be able to open the resulting form or report with your 'filter' in the 'where condition' component of the OpenForm statement. This component of the statement allows the same flexibility of a WHERE clause in an SQL statement, but just leave the WHERE keyword out because you don't need it here. Access will place your filter into the form/report's filter property.

Just set this component in code before you call the DoCmd.OpenForm statement, asfollows:

dim strWHERE as string

strWHERE = "Sal > " & varSal
'or
strWHERE = "Sal > " & varSal $ " AND job = '" & varJob & "'"
DoCmd.OpenForm "frmTest", acNormal, , strWHERE

(or you could just use the filter property of the OpenForm to use the form's filter mechanism...)

Don't know if I've really answered your question, but I hope it helps.

This discussion is closed to new replies.