A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Filtering Records on a form using multiple combo boxes



 
 
Thread Tools Display Modes
  #1  
Old June 17th, 2004, 03:57 PM
Mark Senibaldi
external usenet poster
 
Posts: n/a
Default Filtering Records on a form using multiple combo boxes

Does anyone know how to use multiple combo boxes to filter records on a form?

Example:
Combo Box 1- States
Combo Box 2 - Cities (dependant on combo box 1)

I have a table with contacts in the US and I want to be able to mix and match values in the combo box with matching records showing up on the form.
For Example if I choose New York in the first combo box- I want the form to show all New York Contacts, then If I choose Albany in the 2nd combo box I want the records filtered out further to only show contacts in Albany, New York.

Any thoughts?

Thanks in advance.
--
MSS
  #2  
Old June 17th, 2004, 07:05 PM
George Nicholson
external usenet poster
 
Posts: n/a
Default Filtering Records on a form using multiple combo boxes

(This is very rough aircode, and is only one possible approach.)

Dim mstrFormFilter as string
Dim mstrCityFilter as string
Dim mstrStateFilter as string

sub cboCity_AfterUpdate
mstrCityFilter = "= '" & cboCity & "'"
Call SetFilter
end sub

sub cboState_AfterUpdate
mstrStateFilter = "= '" & cboState & "'"
Call SetFilter
end sub

sub SetFilter
' Allow for wildcards: don't assume a selection has been made in both
combos.
if len(mstrStateFilter) = 0 then mstrStateFilter = "Like *"
if len(mstrCityFilter) = 0 then mstrCityFilter = "Like *"
mstrFormFilter = "[State] " & mstrStateFilter & "' AND [City] " &
mstrCityFilter & "'"
Me.Filter = mstrFormFilter
Me.FilterOn = True
end sub
--
George Nicholson

Remove 'Junk' from return address.
"Mark Senibaldi" wrote in message
...
Does anyone know how to use multiple combo boxes to filter records on a

form?

Example:
Combo Box 1- States
Combo Box 2 - Cities (dependant on combo box 1)

I have a table with contacts in the US and I want to be able to mix and

match values in the combo box with matching records showing up on the form.
For Example if I choose New York in the first combo box- I want the form

to show all New York Contacts, then If I choose Albany in the 2nd combo box
I want the records filtered out further to only show contacts in Albany, New
York.

Any thoughts?

Thanks in advance.
--
MSS



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:59 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.