Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use a command button to apply a filter 2

Status
Not open for further replies.

EllieFant

MIS
May 15, 2001
513
US
Yet again another question:

I was hoping that I had learned enough that I could solve this simple problem by myself, but guess I haven't :-(

I want to apply a filter with a predefined condition by clicking on a command button. I have tried different types of statements and they all return the same results - no records - even though I know there are 385 records it should be showing me.

This is the code I tried using:

DoCmd.ApplyFilter , Me.AccessType = "PRP"

AccessType is a text field that has UAP or PRP in the field.

What am I doing wrong?

Thanks!

Ellie
**Using Access 97 at work**
**Using Access 2000 at home**

elliefant@qwest.net
 
Hi,

I know another way of doing this, you could do something like this in the code

dim strSQL as string

strSQL = &quot;SELECT * FROM table WHERE <put your filter here>

me.recordsource = strSQL
me.requery

Hope this helps

Nowell
 
You don't need to change the recordsource.
All you need is this:

Dim sSQL as String

sSQL=&quot;[AccessType] = 'PRP'&quot;
Me.Filter=sSQL
Me.FilterOn=True


If you now replace 'PRP' with some variable, e.g.:
sSQL=&quot;[AccessType] = '&quot; & Me.MyFilter & &quot;'&quot;
Then you can choose your Filter (PRP,UAP, whatever) in a combobox which in this case would be named &quot;MyFilter&quot;.
OK?
[pipe]

MakeItSo


Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
Yeah ok mate,
was just offering a different way of doing things, both ways are exactly the same in terms of overhead,

Your way still has to requery anyway, so whats the difference!

Maybe you should stop smoking so much!

 
Nope, there's no need to requery.
Plus: with Access 97 I try to avoid using recordsets if possible because of the record locking behavior of Access 97.
Sure: If you take good care the danger is nill - but I always count with the worst case.
P.S: Didn't mean to offend you and your approach. OK?:)
P.P.S:
Not only do I smoke, I also drink like hell!
[cheers]
 
Hi again,

Ha ha

No you don't actually have to call a requery command but when you set filter on to true it forces the query to re-run, otherwise how would it filter?

Anyway I need a smoke too and a beer!

Cheers
 
Thank you both for your assistance. I got it to work and I learned something too...bonus!!

Please accept a star for you both.


Ellie
**Using Access 97 at work**
**Using Access 2000 at home**

elliefant@qwest.net
 
DoCmd.ApplyFilter , Me.AccessType = &quot;PRP&quot;

Change to

docmd.ApplyFilter,,&quot;AccessType='PRP'&quot;

See if that works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top