Filter On Open of Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created several forms varying by Location data in one database. Then
each form has a specific filter for that Location data. So once the form is
opened the user has to click the Filter icon and the preset filter is
applied. I know this may not have been the best way to go about this but
since I already have, is there a way the filter can automatically be applied
on open. Would an OnOpen Event work and how or what's the best way?

Thanks,
Kristine
(Learning as I go)
 
Kristine,
the answer to your question is to put this line in the OnOpen event of your
form:
Me.FilterOn = True

Here's a suggestion for a better way to do it:
(I'm assuming that each of your separate forms shows the same thing, just
with different filters.)
Make a header section in your form, and in the header put a combobox that
has all the different locations as its rowsource. (sounds like not that many
if you have a separate form for each) Your combo box's rowsource could be a
query that gets all the location names, like :
SELECT DISTINCT locationName from SomeTable
(you can just type this into the rowsource property of the combobox)

Lets say this combobox is called cboSelection. Then in its afterupdate
event, you could put this line:

DoCmd.ApplyFilter , "Location= '" & Me.cboSelection & "'"

and your one form would filter itself based on the combobox choice. A lot
simpler than a separate form for each filter, no?

hth
-John
 
Fabulous! That first bit was exactly what I needed!

I should try and am right at a point that is ideal to switch to your
suggestion but it's not entirely clear. I have people using the form to enter
data and then others who need to retreive that data but only for specific
locations. I already have the combobox you mention which it seems like would
work but, would everyone go into the form totally unfiltered and then once
they choose the location from the combobox it would automatically filter? The
possibility of error is greater if they have access to all data before
filtering. Can a query be used or something so they can type in the location
they need before the form opens? If not, with your help, what I have is doing
exatcly what I need, since I've made all those forms already. Too bad I
didn't ask about that part before eh?

Thanks again!
 
You can make the detail section invisible until they choose a location in
the combobox. That way, they'll just see the form header until they choose.
You can make the detail section invisible either by going to the property
box of the detail section, under the format tab, or by saying:
me.detail.visible = false
in the on open event of the form
then in the after update event of your combo box:
me.detail.visible=true

hope this helps, and good luck with your project
-john
p.s. you might want to check out a good book on developing Access
applications. The Access Developer's Handbook and "Building Access
Applications" are really good, but kind of advanced. Take a look in a
bookstore or online to see what looks like a good level for you. It might
help save you some time and headaches.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top