Full Version: Difference Between Query And Filter
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
AfroSheen15
Hello,
I'm having a brain cramp today. What is the deference between using a query and a filter? Which would be faster and easier?
Here are two statements basically the same {I think}. BTW- Rot = "B-Days"

CODE
10 stWhere = "position IN ('custody','sgt','lieutenant','captain','other')" & _
          "and shift IN ('B-Days','Day Shift')"

100          Me.Filter = "position IN ('custody','sgt','lieutenant','captain') and shift IN ('" & Rot & "','day shift')"
110          Me.FilterOn = True


If the query is faster then I take it the "stWhere" would go in the "Record Source"? If not then where would I put it?

Thanks
pere_de_chipstick
Hi AfroSheen15

You can have a form with either a query which has criteria, or your form can be based on a query (or table) without criteria but using a form filter to achieve the same results; the differnece in speed is probably not worth worrying about.

So which is better?
IMHO, it is better to use queries (or tables) without criteria and then specify the criteria as a filter string because it makes your database more flexible - you can create your criteria in code dynamically and then apply that filter to a form (Me.Filter = SomeFilterString) or when opening a form or report:
DoCmd.OpenReport "YourReportName",,, SomeFilterString
OR
DoCmd.OpenForm "YourFormName",,, SomeFilterString

This means you can use the same (or similar) forms or reports which are based on the same query and then reduce the number of Access Objects in your db.

JOPO (Just One Person's Opinion)

hth
AfroSheen15
Thanks for your reply. Your IMHO was enlightening.

Thank you again.
pere_de_chipstick
yw.gif
Good luck with your project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.