473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Combo Box to Filter Records in a Continuous Form

Hi all! My (relatively small) database holds data on staff members and
the projects (services) that they are assigned to.

In my form frmStaff, I have a list of staff members - it is a
continuous form. Each staff member is linked to a Service through a
many-to-many relationship, using a junction table called
jctStaffServices. I would like to place a Combo Box in frmStaff where
you can 'filter' staff by the Service (i.e. ServiceName) that they are
assigned to.

What would be the easiest way to achieve this?

I'm presuming that I need to enter code in the AfterUpdate of the Combo
Box?
My tables are structured as follows:
tblStaff:
- Staff_ID (Autonumber)
- EmployeeNo (Primary Key)
- Surname
- FirstName
- etc...
tblServices:
- Service_ID (Autonumber)
- ServiceCode (Primary Key)
- ServiceName
- Address
- etc...
jctStaffServices:
- EmployeeNo
- ServiceNo
My Combo Box is called SelectCombo, and the Row Source is currently:

SELECT DISTINCTROW tblServices.ServiceName
FROM (tblStaff INNER JOIN tblServices ON tblStaff.ServiceCode =
tblServices.ServiceCode) INNER JOIN jctStaffServices ON
(tblStaff.EmployeeNo = jctStaffServices.EmployeeNo) AND
(tblServices.ServiceCode = jctStaffServices.ServiceCode)
ORDER BY tblServices.ServiceName;
Hope all this makes sense. Any help would be greatly appreciated.

PS I'm a newbie so apologies if my description of the problem isn't the
best!

Nov 13 '05 #1
3 12461
See:
Filter a Form on a Field in a Subform
at:
http://allenbrowne.com/ser-28.html

The article explains how to dynamically change the RecordSource of the main
form to an INNER JOIN, so it contains only records that have a match in the
subform. It is also possible to use a subquery in the Filter of the form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Stewart" <st*****@v6media.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi all! My (relatively small) database holds data on staff members and
the projects (services) that they are assigned to.

In my form frmStaff, I have a list of staff members - it is a
continuous form. Each staff member is linked to a Service through a
many-to-many relationship, using a junction table called
jctStaffServices. I would like to place a Combo Box in frmStaff where
you can 'filter' staff by the Service (i.e. ServiceName) that they are
assigned to.

What would be the easiest way to achieve this?

I'm presuming that I need to enter code in the AfterUpdate of the Combo
Box?
My tables are structured as follows:
tblStaff:
- Staff_ID (Autonumber)
- EmployeeNo (Primary Key)
- Surname
- FirstName
- etc...
tblServices:
- Service_ID (Autonumber)
- ServiceCode (Primary Key)
- ServiceName
- Address
- etc...
jctStaffServices:
- EmployeeNo
- ServiceNo
My Combo Box is called SelectCombo, and the Row Source is currently:

SELECT DISTINCTROW tblServices.ServiceName
FROM (tblStaff INNER JOIN tblServices ON tblStaff.ServiceCode =
tblServices.ServiceCode) INNER JOIN jctStaffServices ON
(tblStaff.EmployeeNo = jctStaffServices.EmployeeNo) AND
(tblServices.ServiceCode = jctStaffServices.ServiceCode)
ORDER BY tblServices.ServiceName;
Hope all this makes sense. Any help would be greatly appreciated.

PS I'm a newbie so apologies if my description of the problem isn't the
best!

Nov 13 '05 #2
Stewart wrote:
Hi all! My (relatively small) database holds data on staff members and
the projects (services) that they are assigned to.

In my form frmStaff, I have a list of staff members - it is a
continuous form. Each staff member is linked to a Service through a
many-to-many relationship, using a junction table called
jctStaffServices. I would like to place a Combo Box in frmStaff where
you can 'filter' staff by the Service (i.e. ServiceName) that they are
assigned to.

What would be the easiest way to achieve this?

I'm presuming that I need to enter code in the AfterUpdate of the Combo
Box?
My tables are structured as follows:
tblStaff:
- Staff_ID (Autonumber)
- EmployeeNo (Primary Key)
- Surname
- FirstName
- etc...
tblServices:
- Service_ID (Autonumber)
- ServiceCode (Primary Key)
- ServiceName
- Address
- etc...
jctStaffServices:
- EmployeeNo
- ServiceNo
My Combo Box is called SelectCombo, and the Row Source is currently:

SELECT DISTINCTROW tblServices.ServiceName
FROM (tblStaff INNER JOIN tblServices ON tblStaff.ServiceCode =
tblServices.ServiceCode) INNER JOIN jctStaffServices ON
(tblStaff.EmployeeNo = jctStaffServices.EmployeeNo) AND
(tblServices.ServiceCode = jctStaffServices.ServiceCode)
ORDER BY tblServices.ServiceName;
Hope all this makes sense. Any help would be greatly appreciated.

PS I'm a newbie so apologies if my description of the problem isn't the
best!


I would create a combo box with a rowsource of jctStaffServices and
tblServices that would contain the ServiceID and ServiceName. I would
make it Distinct (or use a totals query) and order by ServiceName. I
might even have a row that has All Services to you can remove the
filter. Ex:

Select EmpID, EmpName From Employees Order By EmpName
UNION
Select 0, "*All Employees" As EmpName From Employees

The above selects all records from the table and floats all employees to
the top of the list. You can do something similar with yours.

In your forms Recordsource you would create a filter. Let's say the
form is called MainForm and the combo is called Combo0. Set it's
default value to 0. Find the column for the ServiceID and in the
criteria row enter
Forms!MainForm!Combo0
This will filter all records in the form to the value in the combo box.

Now, create another column in the recordsource query and enter
Forms!MainForm!Combo0
In the criteria row BELOW the first criteria enter
0

You have now created an OR condition. Only select records that have a
serviceID equal to the combo box OR if combo is 0 then select all records.

In the AfterUpdate event of the combo you could then enter
Me.Requery

This will refilter your records.

You could forget putting in the filter in the recordsource query and in
the afterupdate event put in something like
If Me.Combo0 > 0 then
Me.Filter = "ServiceID = " & Me.Combo0
Else
Me.Filter = ""
Endif
Me.FilterOn = True
to create the filter
Nov 13 '05 #3
Cheers! Thanks to both your help - I've now resolved the problem.

The fix was as follows:

Private Sub SelectCombo_AfterUpdate()
Dim strSQL As String
If IsNull(Me.SelectCombo) Then
Me.RecordSource = "tblStaff"
Else
strSQL = "SELECT DISTINCTROW tblStaff.* FROM tblStaff INNER JOIN
jctStaffServices ON tblStaff.EmployeeNo = jctStaffServices.EmployeeNo
WHERE
(((jctStaffServices.ServiceCode)=[Forms]![newfrmStaff]![SelectCombo]));"
Me.RecordSource = strSQL
End If
End Sub

The row source is set to tblServices. The Bound Column is the
ServiceCode.

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: B | last post by:
I know there are several ways to speed up combo boxes and form loading. Most of the solutions leave rowsource of the combo box blank and set the rowsource to a saved query or an SQL with a where...
0
by: Jeremy Wallace | last post by:
Folks, Here's a write-up I did for our developer wiki. I don't know if the whole rest of the world has already figured out how to do this, but I hadn't ever seen it implemented, and had spent a...
5
by: jjyconsulting | last post by:
Newbie needing some help. I have a tblParticipants. The fields include gender, education_level, income, occupation etc., I'm trying to create a form where a user can run a query from the form and...
8
by: salad | last post by:
I was wondering how you handle active/inactive elements in a combo box. Let's say you have a combo box to select an employee. Joe Blow has been selected for many record however Joe has left the...
4
by: virtualgreek | last post by:
Dear All, First of all I would like to take the time to thank you all for your efforts and time spent at this wonderful forum. I have found it very helpful with numerous examples available for...
1
by: bwakefield | last post by:
Hello, I am currently working on a Stock Control database and I am trying to set a filter on the form using a combo box. At present I am using a continuous form with the combo box being placed in...
6
by: bammo | last post by:
MS Access 2003, Windows XP SP2, VBA I have a continuous form that allows edits and filters, but not deletions or additions. I filter the form based on combining selections the user makes in...
14
kcdoell
by: kcdoell | last post by:
Hello: I have a form (Default view =single form) with a subform (Default view =continuous forms) embedded into it. In the form I have three controls that display the Division, Working Region &...
1
by: zufie | last post by:
Hi, When I make a selection from the drop down list of values on a Combo Box. The Combo Box is on a Form. The Combo Box selection appears on ALL of the records. That is, when I select one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.