Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

Filter by ID

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel - 11 May 2007 15:27 GMT
Hi,

I am trying to setup a filter on my form that filters when a command button
is clicked.  I have a combo box that lists the various column names which are
products a company might have.  When the button is pressed, I want it to look
at what the value is in the combo box, and then search through each record
and determine if that company has the chosen product.  I am unsure how to
write the code for this.  Any help is appreciated.

Thanks
Carl Rapson - 11 May 2007 17:14 GMT
> Hi,
>
[quoted text clipped - 9 lines]
>
> Thanks

To clarify: you are wanting to only display those companies that have the
product selected in the combo box, right? What is the RecordSource of the
form? How are companies and products related - one to one or one to many?
Normally, a company can have multiple products, so the table design is to
have a table for companies and another table for products, with the company
ID being a foreign key in the products table. Is this your setup?

Assuming it is, here is what I normally do. In the Click event of the
button, change the form's RecordSource to add the filter as a WHERE clause.
I've broken this into several parts so you can see what's going on:

Dim strSQL As String

strSQL = "SELECT * FROM [companies table]"
strSQL = strSQL & " WHERE [company id field] IN "
strSQL = strSQL & "(SELECT [company id field] FROM [products table]"
strSQL = strSQL & " WHERE [product id field]=" & combobox & ")"
Me.RecordSource = strSQL

Of course, you'll need to modify this to use your own table, field, and
control names. Also if the the company id and/or product id fields are text
instead of numeric, you'll need to add appropriate quotes around their
values when building the SQL string.

Carl Rapson
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.