473,721 Members | 2,254 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 6906
mlcampeau
296 Recognized Expert Contributor
Okay, now my question is this. I created my queries in the query design view, not in vba. Does that make a difference? Would I just add the textbox reference to my already existing query or should I have created the report based on a query written in vba?
Changing my MY - JobVacancies query to:
Expand|Select|Wrap|Line Numbers
  1. SELECT JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode, JobVacancy.NumberofPositions, Department.Desc, Division.Desc, Reports![JobVacanciesOnly]![JobVacanciesOnlySR].Report![NumVacancies]
  2. FROM (JobVacancy LEFT JOIN Department ON JobVacancy.DepartmenCode = Department.Code) LEFT JOIN Division ON JobVacancy.DivisionCode = Division.Code
  3. WHERE Reports![JobVacanciesOnly]![JobVacanciesOnlySR].Report![NumVacancies]>0
  4. GROUP BY JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode, JobVacancy.NumberofPositions, Department.Desc, Division.Desc, Reports![JobVacanciesOnly]![JobVacanciesOnlySR].Report![NumVacancies]
  5. ORDER BY JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode;
and my MY - JobVacancyJobs query to:
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, Reports!JobVacanciesOnly![TotalVacancies] AS TotalVac
  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. WHERE Reports!JobVacanciesOnly![TotalVacancies]>0
  4. ORDER BY Job.Title, Job.Code;
doesn't cause any errors. The report opens, but doesn't display any info. All fields on the main report are blank except Title which shows #Error and nothing on the subreport displays.
Aug 1 '07 #31
puppydogbuddy
1,923 Recognized Expert Top Contributor
Whether you did it in design view on the query grid or used VBA should not have made any difference because Access will convert the grid to executable sql. I assume that your ReportOpen code just used the basic DoCmd.Open report syntax. Try commenting out all your ReportOpen code and open the report manually by clicking on the report itelf from the Access Report Window.

I will do some more research tomorrow. I know there are other alternatives, like creating NumVacancies and TotalVacancies as alias items in the applicable query instead of referencing to the textbox. To do this go to your query grid for each select statement, create an alias column as shown:
NumVacancies:DL ookup......blah ...blah
then like before, put > 0 in the criteria row. This method should definitely work because it should show the results in your query, when you run the query by itself.
Aug 1 '07 #32
mlcampeau
296 Recognized Expert Contributor
I assume that your ReportOpen code just used the basic DoCmd.Open report syntax. Try commenting out all your ReportOpen code and open the report manually by clicking on the report itelf from the Access Report Window.
I do not have any ReportOpen code. I open the report from the Access Report Window right now and do not have any forms or buttons to click in order to open it.
Aug 2 '07 #33
puppydogbuddy
1,923 Recognized Expert Top Contributor
I do not have any ReportOpen code. I open the report from the Access Report Window right now and do not have any forms or buttons to click in order to open it.

Ok, then. did you try the alias column in query method I suggested in the same post?
Aug 2 '07 #34
mlcampeau
296 Recognized Expert Contributor
I know there are other alternatives, like creating NumVacancies and TotalVacancies as alias items in the applicable query instead of referencing to the textbox. To do this go to your query grid for each select statement, create an alias column as shown:
NumVacancies:DL ookup......blah ...blah
then like before, put > 0 in the criteria row. This method should definitely work because it should show the results in your query, when you run the query by itself.
I can't seem to get the DLookup to work proper. I tried Dlookup, but then changed it to DCount (since I want the number to do the math) and I'm getting the same problem. I tried the following code in order to get the total number of occupants for each position in each division so that I can subtract it from the Number of Positions, in order to get the number of vacancies:
TotalOccupants: DCount("[MY - JobVacancyOccup ants]![ID]","MY - JobVacancyOccup ants")
That code gives me a number of 610 for every record in the query. (It's basically counting every employee once for each and every job title in the database) I then tried adding criteria in the code:
TotalOccupants: DCount("[MY - JobVacancyOccup ants]![ID]","MY - JobVacancyOccup ants","[MY - JobVacancyOccup ants]![JobCode]=[Job]![code]")
I get an error: The expression you entered as a query parameter produced this error: 'HRSource can't find the name 'Job!Code' you entered in the expression'.
I tried different syntax like [Job].[code], Code, Job.Code and they all give the same error. Same thing happens if I try to add criteria regarding the division.
This is starting to get sooo frustrating!! As smart as computers are, I wish they were a little bit smarter! Or maybe it's me that should be a little bit smarter....
Aug 2 '07 #35
puppydogbuddy
1,923 Recognized Expert Top Contributor
I can't seem to get the DLookup to work proper. I tried Dlookup, but then changed it to DCount (since I want the number to do the math) and I'm getting the same problem. I tried the following code in order to get the total number of occupants for each position in each division so that I can subtract it from the Number of Positions, in order to get the number of vacancies:
TotalOccupants: DCount("[MY - JobVacancyOccup ants]![ID]","MY - JobVacancyOccup ants")
That code gives me a number of 610 for every record in the query. (It's basically counting every employee once for each and every job title in the database) I then tried adding criteria in the code:
TotalOccupants: DCount("[MY - JobVacancyOccup ants]![ID]","MY - JobVacancyOccup ants","[MY - JobVacancyOccup ants]![JobCode]=[Job]![code]")
I get an error: The expression you entered as a query parameter produced this error: 'HRSource can't find the name 'Job!Code' you entered in the expression'.
I tried different syntax like [Job].[code], Code, Job.Code and they all give the same error. Same thing happens if I try to add criteria regarding the division.
This is starting to get sooo frustrating!! As smart as computers are, I wish they were a little bit smarter! Or maybe it's me that should be a little bit smarter....

LOL!! It can be frustrating at times, but if you have patience you will find the solution.

I am not sure why you need the second expression referenced above, because whatever level [ID] is on is the level that you will get the output. Nevertheless, I revised the second expression, assuming that Code is numeric, and also reivised assuming that [code] is a text data type.

By the way, it is not good practice to have spaces and hyphens in object names because Access will require references to these names to be enclosed with brackets. A better practice for creating Names should be like this:
MyJobVacancyOcc upants
or
My_JobVacancyOc cupants

TotalOccupants: DCount("[ID]","[MY - JobVacancyOccup ants]")

Revised syntax for your second expression, assuming that [code] is numeric.
TotalOccupants: DCount("[ID]","[MY - JobVacancyOccup ants]","[code] = “ & [Job]![code])

Revised syntax for your second expression, assuming that [code] is text.
TotalOccupants: DCount("[ID]","[MY - JobVacancyOccup ants]","[code] = “ & [Job]![code] & “’”
Aug 2 '07 #36
mlcampeau
296 Recognized Expert Contributor
Thanks for the info on the names of my queries. I wasn't planning on keeping the names that way - I was just trying to keep track of the queries that I had added to this database so they were easier for me to locate so I started them all with my initials.
As for the code...
Expand|Select|Wrap|Line Numbers
  1. TotalOccupants: DCount("[ID]","[MY - JobVacancyOccupants]")
gives me 610 in every record (so 610 occupants for each and every job code in the database)
I tried changing that to
[code]TotalOccupants: DCount("[ID]","[MY - JobVacancyOccup ants]","[code] = “ & [Job]!
Expand|Select|Wrap|Line Numbers
  1. )&"'")
in order to try get the DCount to count the ID's where the Job Code in the MY - JobVacancyOccup ants query matches the job code in the Job table. I get a message box asking me to enter the parameter value for Job!Code.
The rest of my sql query looks like this:
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. ORDER BY JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode;
*sigh* I just don't know! Oh, and Job Code is a text field
Aug 2 '07 #37
puppydogbuddy
1,923 Recognized Expert Top Contributor
Thanks for the info on the names of my queries. I wasn't planning on keeping the names that way - I was just trying to keep track of the queries that I had added to this database so they were easier for me to locate so I started them all with my initials.
As for the code...
Expand|Select|Wrap|Line Numbers
  1. TotalOccupants: DCount("[ID]","[MY - JobVacancyOccupants]")
gives me 610 in every record (so 610 occupants for each and every job code in the database)
I tried changing that to
[code]TotalOccupants: DCount("[ID]","[MY - JobVacancyOccup ants]","[code] = “ & [Job]!
Expand|Select|Wrap|Line Numbers
  1. )&"'")
in order to try get the DCount to count the ID's where the Job Code in the MY - JobVacancyOccup ants query matches the job code in the Job table. I get a message box asking me to enter the parameter value for Job!Code.
The rest of my sql query looks like this:
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. ORDER BY JobVacancy.JobCode, JobVacancy.DepartmenCode, JobVacancy.DivisionCode;
*sigh* I just don't know! Oh, and Job Code is a text field

We'll get there. Looked at your query and realized it is JobCode not Job!Code
so, try this:

TotalOccupants: DCount("[ID]","[MY - JobVacancyOccup ants]","[JobCode] = '" & [JobVacancy]![JobCode] &"'")
Aug 2 '07 #38
mlcampeau
296 Recognized Expert Contributor
We'll get there. Looked at your query and realized it is JobCode not Job!Code
so, try this:

TotalOccupants: DCount("[ID]","[MY - JobVacancyOccup ants]","[JobCode] = '" & [JobVacancy]![JobCode] &"'")
Okay, well, this just proved that I'm losing my mind. Completely ignore my last post because I was putting the information in the wrong query!! That query is what my subreport is based on, and I'm trying to work on the TotalOccupants based on the query of the main report. So.....When I try
[code]TotalOccupants: DCount("[ID]","[MY - JobVacancyOccup ants]","[JobCode] = '" & [Job]!
Expand|Select|Wrap|Line Numbers
  1.  &"'")
low and behold, it gives me the total occupants for that position!! Now I just need to figure out the correct expression to subtract that from JobVacancy.Numb erofPositions.
And, FYI, the query for the main report is now
[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]!
Expand|Select|Wrap|Line Numbers
  1.  & "'") AS TotalOccupants
  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;
Aug 2 '07 #39
mlcampeau
296 Recognized Expert 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!!
Aug 2 '07 #40

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

Similar topics

0
6473
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
6283
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
17667
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
2738
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
4400
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
2487
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
4740
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
5540
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
8840
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
9215
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
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6669
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5981
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
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
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
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
2130
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.