Vba help: Cmd Button that filters on a fixed text value...

L

Lynndyhop

Hi there!

I am trying to build an event for a command button that filters visable
records in a form by a specific text value appearing in a field within that
form. Needing some help with the vba for this.....

The data table the form is based on is ContactsDataMain and the field is
MemberCategory, and the value is 'Category 2'. Any help would be appreciated!

Many thanks,

Lynndyhop
 
D

Dale Fye

Lynndy,

The code behind your command button will look something like:

Private Sub cmd_Filter_Click

dim strSQL as string

strSQL = "[MemberCategory] = '" & me.txt_Filter & "'"
me.filter = strsql
me.filteron = true

end sub

You might want to consider adding a "Clear Filter" button, or modifying the
code on your filter button so that it changes the caption of the button when
you click it, and takes the appropriate action.

Private Sub cmd_Filter_Click

dim strSQL as string

if me.cmd_Filter.Caption = "&Filter" then
strSQL = "[MemberCategory] = '" & me.txt_Filter & "'"
me.filter = strsql
me.filteron = true
me.cbo_Filter.Caption = "Clear &Filter"
else
me.filter = ""
me.filteron = false
me.cbo_Filter.Caption = "&Filter"
endif

End sub

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

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