473,725 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filter report based on values of calculated value on report

296 Recognized Expert Contributor
I have a report (JobVacanciesOn ly) that has a subreport (JobVacanciesOn lySR) that are based on two separate queries.
MY - JobVacancyJobs
Expand|Select|Wrap|Line Numbers
  1. SELECT Job.Code, Job.Title, Job.Grade, Grade.Minimum, Grade.Midpoint, Grade.Maximum, Job.EEOCategoryCode, EEOCategory.Desc, Job.EEOSubCategoryCode, EEOSubCategory.Desc
  2. FROM Grade RIGHT JOIN (EEOSubCategory RIGHT JOIN (EEOCategory RIGHT JOIN Job ON EEOCategory.Code = Job.EEOCategoryCode) ON EEOSubCategory.Code = Job.EEOSubCategoryCode) ON Grade.Code = Job.Grade
  3. ORDER BY Job.Title, Job.Code;
MY - JobVacancies
Expand|Select|Wrap|Line Numbers
  1. SELECT JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode, JobVacancy.NumberofPositions, Department.Desc, Division.Desc
  2. FROM (JobVacancy LEFT JOIN Department ON JobVacancy.DepartmenCode = Department.Code) LEFT JOIN Division ON JobVacancy.DivisionCode = Division.Code
  3. GROUP BY JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode, JobVacancy.NumberofPositions, Department.Desc, Division.Desc
  4. ORDER BY JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode;
There is a textbox on the main report that calculates the total number of vacancies for each job position
[code]TotalVacancies= IIf(((DSum("[NumberofPositio ns]","JobVacan cy", "[JobVacancy.JobC ode]=[code]"))-DCount("[MY - ActiveEmpJob]![ID]","MY - ActiveEmpJob"," [MY - ActiveEmpJob]![JobCode] =[code]"))<0,0,((DSum( "[NumberofPositio ns]","JobVacan cy", "[JobVacancy.JobC ode]=[code]"))-DCount("[MY - ActiveEmpJob]![ID]","MY - ActiveEmpJob"," [MY - ActiveEmpJob]![JobCode] =
Expand|Select|Wrap|Line Numbers
  1. ")))
and a textbox in the subreport that calculates the number of vacancies for that job position, in a specific department and division
[code]NumVacancies=II f([NumberofPositio ns]-(DCount(" [MY - ActiveEmpJob]![ID]","MY - ActiveEmpJob"," [MY - ActiveEmpJob]![JobCode] = Reports![JobVacanciesOnl y]![code] AND [MY - ActiveEmpJob]![DivisionCode] = [MY - JobVacancies]![DivisionCode] "))<0,0,[NumberofPositio ns]-(DCount(" [MY - ActiveEmpJob]![ID]","MY - ActiveEmpJob"," [MY - ActiveEmpJob]![JobCode] = Reports![JobVacanciesOnl y]!
Expand|Select|Wrap|Line Numbers
  1.  AND [MY - ActiveEmpJob]![DivisionCode] = [MY - JobVacancies]![DivisionCode] ")))
What I want to do now, is filter my report so that when it opens, it only shows the records that have NumVacancies or TotalVacancies with a value greater than 0 (basically I want it to only display the records where there is a job vacancy). It would seem that the easiest method would be to filter this in a query, but after over a week of trying to get a query to calculate the vacancies for me, it seems that with my dataset, it is not possible to get the desired results - hence the 2 queries above. So......is there any way to filter this based on a calculated value textbox that is on the report?? My VBA is very very limited, so please don't oversimplify if that's what I need to be using. Thanks in advance!
Jul 27 '07
94 6912
puppydogbuddy
1,923 Recognized Expert Top Contributor
[code=sql]SELECT Job.Code, Job.Title, Job.Grade, Grade.Minimum, Grade.Midpoint, Grade.Maximum, Job.EEOCategory Code, EEOCategory.Des c, Job.EEOSubCateg oryCode, EEOSubCategory. Desc, DCount("[ID]","[MY - JobVacancyOccup ants]","[JobCode] = '" & [Job]![code] & "'") AS TotalOccupants, DSum("[NumberofPositio ns]","JobVacancy", "[JobVacancy]![JobCode]='" & [Job]!
Expand|Select|Wrap|Line Numbers
  1.  & "'") AS TotalPositions, [TotalPositions]-[TotalOccupants] AS TotalVacancies
  2. FROM Grade RIGHT JOIN (EEOSubCategory RIGHT JOIN (EEOCategory RIGHT JOIN Job ON EEOCategory.Code = Job.EEOCategoryCode) ON EEOSubCategory.Code = Job.EEOSubCategoryCode) ON Grade.Code = Job.Grade
  3. ORDER BY Job.Title, Job.Code;
You have NO idea how long I tried making a query that would give me the accurate numbers for TotalOccupants, TotalPositions, TotalVacancies! ! That's why I was calculating them on the report! But it works!!!! Now I need to try doing that with the query for the subform (it'll probably be a bit more difficult cuz the divisions need to match) But thank you thank you thank you for getting me this far!!
Told you you'd get there. Try the subreport computation and let me know one way or another. I will help you with the syntax if you have any trouble. You are on a roll now!
Aug 2 '07 #41
mlcampeau
296 Recognized Expert Contributor
Told you you'd get there. Try the subreport computation and let me know one way or another. I will help you with the syntax if you have any trouble. You are on a roll now!
Okay, the quotes are really screwing me up.
Expand|Select|Wrap|Line Numbers
  1. DCount("[ID]","[MY - JobVacancyOccupants]","[JobCode] = '" & [JobVacancy]![JobCode] "' AND [MY - JobVacancyOccupants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "'") AS NumOccupants
I know they aren't right, but I don't understand them, so if you could help me with where the quotes go then I can try to see if this works. Thanks!!
Aug 2 '07 #42
mlcampeau
296 Recognized Expert Contributor
Okay, the quotes are really screwing me up.
Expand|Select|Wrap|Line Numbers
  1. DCount("[ID]","[MY - JobVacancyOccupants]","[JobCode] = '" & [JobVacancy]![JobCode] "' AND [MY - JobVacancyOccupants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "'") AS NumOccupants
I know they aren't right, but I don't understand them, so if you could help me with where the quotes go then I can try to see if this works. Thanks!!
So I came up with this:
Expand|Select|Wrap|Line Numbers
  1. SELECT JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode, JobVacancy.NumberofPositions, Department.Desc, Division.Desc, DCount("[ID]","[MY - JobVacancyOccupants]","[JobCode] = '" & [JobVacancy]![JobCode] &"' AND [MY - JobVacancyOccupants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "'") AS NumOccupants
  2. FROM (JobVacancy LEFT JOIN Department ON JobVacancy.DepartmenCode = Department.Code) LEFT JOIN Division ON JobVacancy.DivisionCode = Division.Code
  3. ORDER BY JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode;
The problem is the same problem that I had a couple weeks ago when I tried to have a query incorporate the number of occupants. Right now, not every employee has a division entered, and not every job is in the job vacancy table (Yes, life would be easier if it were, but unfortunately, that is the way it is for now) Therefore, by saying [MY - JobVacancyOccup ants]![DivisionCode]='" & [JobVacancy]![DivisionCode] it filters out records that I need. It filters out job codes where employees don't have a division code, and it filters out job codes where the job is not in the Job Vacancy table. Any ideas on how to get it to show all?
Aug 2 '07 #43
puppydogbuddy
1,923 Recognized Expert Top Contributor
So I came up with this:
Expand|Select|Wrap|Line Numbers
  1. SELECT JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode, JobVacancy.NumberofPositions, Department.Desc, Division.Desc, DCount("[ID]","[MY - JobVacancyOccupants]","[JobCode] = '" & [JobVacancy]![JobCode] &"' AND [MY - JobVacancyOccupants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "'") AS NumOccupants
  2. FROM (JobVacancy LEFT JOIN Department ON JobVacancy.DepartmenCode = Department.Code) LEFT JOIN Division ON JobVacancy.DivisionCode = Division.Code
  3. ORDER BY JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode;
The problem is the same problem that I had a couple weeks ago when I tried to have a query incorporate the number of occupants. Right now, not every employee has a division entered, and not every job is in the job vacancy table (Yes, life would be easier if it were, but unfortunately, that is the way it is for now) Therefore, by saying [MY - JobVacancyOccup ants]![DivisionCode]='" & [JobVacancy]![DivisionCode] it filters out records that I need. It filters out job codes where employees don't have a division code, and it filters out job codes where the job is not in the Job Vacancy table. Any ideas on how to get it to show all?

Ok, Try this:

DCount("[ID]","[MY - JobVacancyOccup ants]","[JobCode] = '" & [JobVacancy]![JobCode] & "' AND [MY - JobVacancyOccup ants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "'") AS NumOccupants

As to your second question, it looks to me like you have it correct. Generally a left or right Join is used to pick up all records from one of the tables and only matching records from the other..If the left join is not giving it to you, turn your join into a right join and see if that helps ...

Let me know..
Aug 2 '07 #44
mlcampeau
296 Recognized Expert Contributor
Ok, Try this:

DCount("[ID]","[MY - JobVacancyOccup ants]","[JobCode] = '" & [JobVacancy]![JobCode] & "' AND [MY - JobVacancyOccup ants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "'") AS NumOccupants

As to your second question, it looks to me like you have it correct. Generally a left or right Join is used to pick up all records from one of the tables and only matching records from the other..If the left join is not giving it to you, turn your join into a right join and see if that helps ...

Let me know..
Yes, your code for DCount works (it's actually the same as what I had in my sql query in the previous post, but thanks!) As for the joins, that is definitely not the problem. I only show three tables in design view
Job Vacancy:
JobCode
DepartmenCode
DivisionCode
NumberofVacanci es
Department:
DepartmentCode
Department Description
Division]:
DivisionCode
DivisionDescrip tion

So the joins are just there to be able to get the descriptions of the department and division. Doesn't work if I change it to the other way. What I need the dcount to do is to count the people where JobVacancy.Divi sionCode=
[MY - JobVacancyOccup ants]![DivisionCode] OR [JobVacancy.Divi sionCode] IS NULL OR [MY - JobVacancyOccup ants]![DivisionCode] IS NULL. I hope that would give me the results I'm looking for. I'm just not 100% sure what the syntax would be. I tried
Expand|Select|Wrap|Line Numbers
  1.  DCount("[ID]","[MY - JobVacancyOccupants]","[JobCode] = '" & [JobVacancy]![JobCode] & "' AND (Is Null([MY - JobVacancyOccupants]![DivisionCode]) OR Is Null([JobVacancy]![DivisionCode]) OR [MY - JobVacancyOccupants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "')") AS NumOccupants
but then it displays #Error in that column........
Aug 2 '07 #45
puppydogbuddy
1,923 Recognized Expert Top Contributor
is division code numeric or text?
Aug 2 '07 #46
mlcampeau
296 Recognized Expert Contributor
is division code numeric or text?
DivisionCode is a text field
Aug 2 '07 #47
puppydogbuddy
1,923 Recognized Expert Top Contributor
Yes, your code for DCount works (it's actually the same as what I had in my sql query in the previous post, but thanks!) As for the joins, that is definitely not the problem. I only show three tables in design view
Job Vacancy:
JobCode
DepartmenCode
DivisionCode
NumberofVacanci es
Department:
DepartmentCode
Department Description
Division]:
DivisionCode
DivisionDescrip tion

So the joins are just there to be able to get the descriptions of the department and division. Doesn't work if I change it to the other way. What I need the dcount to do is to count the people where JobVacancy.Divi sionCode=
[MY - JobVacancyOccup ants]![DivisionCode] OR [JobVacancy.Divi sionCode] IS NULL OR [MY - JobVacancyOccup ants]![DivisionCode] IS NULL. I hope that would give me the results I'm looking for. I'm just not 100% sure what the syntax would be. I tried
Expand|Select|Wrap|Line Numbers
  1.  DCount("[ID]","[MY - JobVacancyOccupants]","[JobCode] = '" & [JobVacancy]![JobCode] & "' AND (Is Null([MY - JobVacancyOccupants]![DivisionCode]) OR Is Null([JobVacancy]![DivisionCode]) OR [MY - JobVacancyOccupants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "')") AS NumOccupants
but then it displays #Error in that column........

Try this and let me know. Your main problem was with Is Null. When used as a function, the syntax is "IsNull()"; when used as a criteria, the syntax is "Is Null"
Expand|Select|Wrap|Line Numbers
  1. DCount("[ID]","[MY - JobVacancyOccupants]","[JobCode] = '" & [JobVacancy]![JobCode] & "' AND (IsNull([MY - JobVacancyOccupants]![DivisionCode]) OR IsNull([JobVacancy]![DivisionCode]) OR [MY - JobVacancyOccupants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "')") AS NumOccupants
Aug 2 '07 #48
mlcampeau
296 Recognized Expert Contributor
Try this and let me know. Your main problem was with Is Null. When used as a function, the syntax is "IsNull()"; when used as a criteria, the syntax is "Is Null"
Expand|Select|Wrap|Line Numbers
  1. DCount("[ID]","[MY - JobVacancyOccupants]","[JobCode] = '" & [JobVacancy]![JobCode] & "' AND (IsNull([MY - JobVacancyOccupants]![DivisionCode]) OR IsNull([JobVacancy]![DivisionCode]) OR [MY - JobVacancyOccupants]![DivisionCode]='" & [JobVacancy]![DivisionCode] & "')") AS NumOccupants
Yeah, I caught that I had a space in there but it was still providing errors after I fixed it. I'll try the rest of your syntax in the morning, since it's time to head home!
ps - I think I'm going for the record for the longest thread!
Aug 2 '07 #49
puppydogbuddy
1,923 Recognized Expert Top Contributor
Longest thread.......no t even close!! IsNull may not do what you want ...if it doesn't, then use the IS Null criteria syntax.....

([MY - JobVacancyOccup ants]![DivisionCode] Is Null) OR ........blah blah.
Aug 2 '07 #50

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6474
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the report are based on the same View addressed in the Record Source of both as 'dbo.CLMain_vw'. The View resides in a SQL Server 2000 database. There are two different problems I am having with filtering: The first involves filtering in the form by date...
3
6614
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where the text value is on a different table. The me.filter is then a text instead of the id-number from the lookup table. This causes the report to prompt for the parameter. How do I get by this problem? Do I need to create a temporary table? I rather...
7
6285
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals. I can do this the first time the form loads.
1
17668
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
3
2739
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have reports at the plan (overall totals), department and division levels which have sorting and grouping implemented with this new
2
4402
by: Seth Delaney | last post by:
I have a form with multiple unbound text boxes which serves as a "search form". I can enter my search parameters in the various boxes as needed and click okay. My records are then filtered to produce the results I want in a separate form (filter by form). No problem, except I want to save the sql to a query, not a form. When I debug.print the various sql, I get something like this example: (( LIKE "cam*")) which obviously is not enough...
1
2488
by: shobhit_shanker | last post by:
Here are the relevant "givens" to my problem... Form: frmLaunchRpt - Text Box: txtAsOfDate - Check Box: chkLogEval - Command Button: cmdLaunchRpt Report: rptEvaluation - Text Box: txtGreen (Percent of items on schedule) - Text Box: txtYellow (Percent of items slightly off schedule)
3
4741
by: kelley.l.turner | last post by:
Hi all, I am very new to MS Access so please bear with me! I have created a simple calculated field in my data entry form, yet when I view my data table or try to generate a report based on this calculated field, no value is posted. How/where do I get my calculated values to also show up in the tables and reports? Thanks, Kelley
2
5544
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by Form" in order to search for records based on this form, I would like to be able to enter a value in this "days" control so that I can filter records on the form based on this calculated interval (i.e., i want to search for records specifically where...
0
8888
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.