By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

If a form is filtered, does its recordset include the filter?

Seth Schrock
Expert 2.5K+
P: 2,944
This might sound like a really dumb question. I have a form whose filter changes based on who is logged in (record access control). On this form, I have a textbox that allows me to type in a search number and pull up the record. Right now, I'm using the Me.Recordset.FindFirst method to find the record. Does this recordset include the form's filter? I need it to so that if the user can't go to that record (or the number typed in doesn't match a record) the .NoMatch method will trigger. So my question is, do I need to add my filter to the recordset criteria, or is that already done through the form's filter?
Jan 17 '13 #1

✓ answered by Stewart Ross

Assuming that you are setting the Filter property of the form in code after updating the textbox you mention, the form's recordset does indeed take the filter into account. The filter acts like having an additional WHERE clause on a SELECT statement.

-Stewart

Share this Question
Share on Google+
9 Replies


Expert Mod 2.5K+
P: 2,545
Assuming that you are setting the Filter property of the form in code after updating the textbox you mention, the form's recordset does indeed take the filter into account. The filter acts like having an additional WHERE clause on a SELECT statement.

-Stewart
Jan 17 '13 #2

Seth Schrock
Expert 2.5K+
P: 2,944
The form is filtered in the form's On_Load event. When the textbox uses the Me.Recordset, the form is already filtered.

That is the way that I thought it would, but I just wanted to make sure. Thanks Stewart.
Jan 17 '13 #3

NeoPa
Expert Mod 15k+
P: 31,561
Am I wrong to think it would in all circumstances Stewart?

Normally (certainly in my projects) filtering is applied using the WhereCondition parameter of the DoCmd.OpenForm() call. I would expect the form's Recordset property to reflect that filter.
Jan 17 '13 #4

Expert Mod 2.5K+
P: 2,545
Hi NeoPa. You are quite right that if the form's WhereCondition is set that too will change the recordset. I was unclear from what was posted by Seth how a filter was being applied, and misread it. I thought the filter was applied here:

@Seth: On this form, I have a textbox that allows me to type in a search number and pull up the record
But that is incorrect, as Seth stated in the first part of his post that the filter is by the user logged in, so hence on load.

I should have realised this and clarified that whatever filter or wherecondition is applied will be reflected in the recordset of the form.

-Stewart
Jan 18 '13 #5

TheSmileyCoder
Expert Mod 100+
P: 2,321
I would recommend that you do this filtering of records the user is not allowed to see, by the forms underlying query. I believe that would be safer. Whether the approach you have currently is sufficient, I don't know for sure, since I haven't really tried to brake it.

Make sure however, that you set the forms Allow Filters property to false, otherwise the user can simply remove the filter you applied through code.
Jan 18 '13 #6

Seth Schrock
Expert 2.5K+
P: 2,944
I believe that I don't have to worry about the users removing the filter as they are using Access runtime and I have removed the navigation bar which has the filter on it. I believe this covers all my bases, but I could be wrong.

Anyway, I do have my answer about the filter being included in the Me.Recordset. Thanks everyone. I enjoy reading the discussions between experts as I learn much from it.
Jan 18 '13 #7

TheSmileyCoder
Expert Mod 100+
P: 2,321
I haven't used runtime, but I believe right clicking a enabled field will allow you to filter, provided you have not disabled the regular right click commandbars.

Either way, setting the AllowFilters property to false only affects manual filters as far as I know, this preventing the user from manually editing/adding/disabling the filter you set.
Jan 20 '13 #8

Seth Schrock
Expert 2.5K+
P: 2,944
I had never played with right clicking on a text box, but you are right. There is an option to filter or clear the filter on that field. I will set the AllowFilters property to false. Thank-you for catching that.
Jan 20 '13 #9

TheSmileyCoder
Expert Mod 100+
P: 2,321
I remember someone in online forums who had a signature something like "There is ALWAYS more then 1 way to skin a cat".

I have always liked that saying especially for Access, cause I feel it fits so perfectly.
Jan 20 '13 #10

Post your reply

Sign in to post your reply or Sign up for a free account.