473,569 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
jctStaffService s. 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...
jctStaffService s:
- EmployeeNo
- ServiceNo
My Combo Box is called SelectCombo, and the Row Source is currently:

SELECT DISTINCTROW tblServices.Ser viceName
FROM (tblStaff INNER JOIN tblServices ON tblStaff.Servic eCode =
tblServices.Ser viceCode) INNER JOIN jctStaffService s ON
(tblStaff.Emplo yeeNo = jctStaffService s.EmployeeNo) AND
(tblServices.Se rviceCode = jctStaffService s.ServiceCode)
ORDER BY tblServices.Ser viceName;
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 12484
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*****@v6medi a.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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
jctStaffService s. 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...
jctStaffService s:
- EmployeeNo
- ServiceNo
My Combo Box is called SelectCombo, and the Row Source is currently:

SELECT DISTINCTROW tblServices.Ser viceName
FROM (tblStaff INNER JOIN tblServices ON tblStaff.Servic eCode =
tblServices.Ser viceCode) INNER JOIN jctStaffService s ON
(tblStaff.Emplo yeeNo = jctStaffService s.EmployeeNo) AND
(tblServices.Se rviceCode = jctStaffService s.ServiceCode)
ORDER BY tblServices.Ser viceName;
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
jctStaffService s. 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...
jctStaffService s:
- EmployeeNo
- ServiceNo
My Combo Box is called SelectCombo, and the Row Source is currently:

SELECT DISTINCTROW tblServices.Ser viceName
FROM (tblStaff INNER JOIN tblServices ON tblStaff.Servic eCode =
tblServices.Ser viceCode) INNER JOIN jctStaffService s ON
(tblStaff.Emplo yeeNo = jctStaffService s.EmployeeNo) AND
(tblServices.Se rviceCode = jctStaffService s.ServiceCode)
ORDER BY tblServices.Ser viceName;
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 jctStaffService s 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_Aft erUpdate()
Dim strSQL As String
If IsNull(Me.Selec tCombo) Then
Me.RecordSource = "tblStaff"
Else
strSQL = "SELECT DISTINCTROW tblStaff.* FROM tblStaff INNER JOIN
jctStaffService s ON tblStaff.Employ eeNo = jctStaffService s.EmployeeNo
WHERE
(((jctStaffServ ices.ServiceCod e)=[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
9354
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 clause after users typed in one or several letters/digits. My problem is as follows Most of the time I need to display form in continuous format,...
0
2917
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 lot of time trying to figure it out, over the years. It finally dawned on me a couple of weeks ago how to do this. A couple of notes: 1) This is...
5
3685
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 just choose the appropriate criterias from the combo boxes to get the results. I also want the query to run even if there is not a value in all...
8
8240
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 company and has been flagged inactive. If you have a filter on the rowsource like Where Active = True then Joe's name would not show up in the combo...
4
2898
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 every level of user. I am facing a rather weird behaviour with a combo box on a subform (Continuous form). I have two tables. Order and...
1
1977
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 the header so that it is always viewable. I have put the code in to the form however every time i select anything in the combo box I get an error...
6
4174
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 several combo boxes on the form. The filter is updated whenever the user changes his/her selection. My problem is when the user selects a filter...
14
2321
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 & Credit Region. The subform displays the data/records. The record source for both my form and subform is driven by a query, which is the way I filter...
1
1629
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 value from the Combo Box that value appears in the Combo Box on all the records regardless of what record I am
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.