"Filter by form" vba?

S

StargateFan

In looking over the contacts sample database, which I'm modifying to
fit my needs, I've found how we can search for records. I've figured
out that the switchboard entry seems to actually be the "filter by
form", as you all probably know. But I find that running everything
from the switchboard is extremely cumbersome so would like to add this
feature as a button directly onto the main contacts form itself.
Also, in editing the switchboard item, nothing appears in the boxes
other than the title of the entry so I can't see how the filter by
form was invoked. It doesn't appear in the command box wizard which
I'm wholly dependent on still. I have found where the blank code is,
as I've created the button. So I can put the code in once I've found
it for that button. Where can I look for code such as this, pls? I'm
sorry for all the really newbie questions but I'm not finding things
easy to figure out via the help file (guess I'm still not asking the
right questions there! <g>). Tx.

oh, p.s., forgot to add that it's not desirable behaviour that after
doing a search, the filter remembers what was searched for the next
time one is looking for something. Is there a way to reset this so
that after one has found what one needs, the search is cleared? :blush:D
 
E

Ed Warren

You will want to use VBA code attached to a button on-click event.

Search help for Filter and FilterON values. e.g.

---------------------------------------------------------------the code
below will work similar to the "like function"
Button_OnClickEvent

Me.Filter = [SomeTextField] = "*"&[searchField]&"*"
me.filterON()=true
 
E

Ed Warren

Sorry, I forgot a couple of quotes and amperstands:

Me.Filter = "[SomeTextField] = "& "*" & [searchField] & "*"
Ed Warren said:
You will want to use VBA code attached to a button on-click event.

Search help for Filter and FilterON values. e.g.

---------------------------------------------------------------the code
below will work similar to the "like function"
Button_OnClickEvent

Me.Filter = [SomeTextField] = "*"&[searchField]&"*"
me.filterON()=true
------------------------------------------------------------------

Ed Warren

StargateFan said:
In looking over the contacts sample database, which I'm modifying to
fit my needs, I've found how we can search for records. I've figured
out that the switchboard entry seems to actually be the "filter by
form", as you all probably know. But I find that running everything
from the switchboard is extremely cumbersome so would like to add this
feature as a button directly onto the main contacts form itself.
Also, in editing the switchboard item, nothing appears in the boxes
other than the title of the entry so I can't see how the filter by
form was invoked. It doesn't appear in the command box wizard which
I'm wholly dependent on still. I have found where the blank code is,
as I've created the button. So I can put the code in once I've found
it for that button. Where can I look for code such as this, pls? I'm
sorry for all the really newbie questions but I'm not finding things
easy to figure out via the help file (guess I'm still not asking the
right questions there! <g>). Tx.

oh, p.s., forgot to add that it's not desirable behaviour that after
doing a search, the filter remembers what was searched for the next
time one is looking for something. Is there a way to reset this so
that after one has found what one needs, the search is cleared? :blush:D
 
M

MacDermott

If you want to invoke FilterByForm, the VBA is
DoCmd.RunCommand acCmdFilterByForm
To clear the old filter out, use
DoCmd.RunCommand acCmdClearGrid
 

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

Top