473,748 Members | 4,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating medians in Access 2003 report

Hello Experts!

I am running a report on a query in Access 2003 and I need to get the median(s) for several different fields in the footer of the report. I am currently using this solution from Microsoft (http://support.microso ft.com/kb/210581):

I pasted

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function Median (tName As String, fldName As String) As Single
  3.   Dim MedianDB As DAO.Database
  4.   Dim ssMedian As DAO.Recordset
  5.   Dim RCount As Integer, i As Integer, x As Double, y As Double, _
  6.       OffSet As Integer
  7.   Set MedianDB = CurrentDB()
  8.   Set ssMedian = MedianDB.Openrecordset("SELECT [" & fldName & _
  9.             "] FROM [" & tName & "] WHERE [" & fldName & _ 
  10.             "] IS NOT NULL ORDER BY [" & fldName  & "];")
  11.   'NOTE: To include nulls when calculating the median value, omit
  12.   'WHERE [" & fldName & "] IS NOT NULL from the example.
  13.   ssMedian.MoveLast
  14.   RCount% = ssMedian.RecordCount
  15.   x = RCount Mod 2
  16.   If x <> 0 Then
  17.      OffSet = ((RCount + 1) / 2) - 2
  18.      For i% = 0 To OffSet
  19.         ssMedian.MovePrevious
  20.      Next i
  21.      Median = ssMedian(fldName)
  22.   Else
  23.      OffSet = (RCount / 2) - 2
  24.      For i = 0 To OffSet
  25.         ssMedian.MovePrevious
  26.      Next i
  27.      x = ssMedian(fldName)
  28.      ssMedian.MovePrevious
  29.      y = ssMedian(fldName)
  30.      Median = (x + y) / 2
  31.   End If
  32.   If Not ssMedian Is Nothing Then
  33.      ssMedian.Close
  34.      Set ssMedian = Nothing
  35.   End If
  36.   Set MedianDB = Nothing
  37. End Function
  38.  
  39.  
into a new module and then placed a text box in the footer of the report with the Control Source property set to

=Median("<Table Name>", "<FieldName >")

When I run the report, I get a Parameter Value prompt for Median and then #Error# instead of a value in the report. I've tried several different but similar codes in the module but each time I get the same result. Any suggestions for correcting this problem? What am I doing wrong? Thanks!
Oct 6 '10 #1
14 2631
nico5038
3,080 Recognized Expert Specialist
The "Parameter Value prompt" indicates something is wrong with your fieldname.
When using spaces in a fieldname (best not to) be sure to have surrounding [ and ] around the fieldname!

Nic;o)
Oct 6 '10 #2
Karen D
7 New Member
I don't have any spaces in the fieldname ("FC_1"). The record values for this field are showing correctly throughout the detail of the report and other functions, such as Count(FC_1), are producing appropriate results in the report footer. Thanks!
Oct 6 '10 #3
nico5038
3,080 Recognized Expert Specialist
Strange, I've used the function in my test database in a report group footer and it's returning the Median without any trouble.

Best to start with a compact and repair of your database.

Nic;o)
Oct 6 '10 #4
Karen D
7 New Member
No Change. The only thing else I can think to note is that I'm placing the function in the report footer rather than a group footer. I tried adding it to a group footer but it didn't change the result.
Oct 6 '10 #5
nico5038
3,080 Recognized Expert Specialist
Can you attach a (part of) the not working .mdb so I can check it?

Nic;o)
Oct 6 '10 #6
Karen D
7 New Member
I'm not sure how to attach it to this post but I've pasted a small piece of the database from the query below (the top row contains the field names):

Sample Date FC_1 FC_2 FC_3 FC_4 FC_5
7/19/2010 2.9 2.9 3.6 9.1 93
6/7/2010 2.9 3.6 3.6 9.1 23
4/21/2010 2.9 2.9 2.9 2.9 3.6
3/11/2010 2.9 2.9 2.9 2.9 2.9
12/14/2009 3.6 2.9 3.6 2.9 15
11/2/2009 3.6 2.9 43 93 93
10/13/2009 3.6 2.9 2.9 2.9 240
8/27/2009 9.1 2.9 7.3 2.9 3.6
7/16/2009 2.9 2.9 3.6 2.9 2.9
6/1/2009 2.9 2.9 2.9 2.9 14
4/21/2009 2.9 2.9 2.9 2.9 7.3
3/19/2009 2.9 2.9 2.9 3 2.9

This is just a small subset of both the fields and records in the actual query database. I need to obtain the median for each of the "FC_*" fields at the end of my report. I should point out that some of the records in each field are blank, so I'm also dealing with null values that I want to exclude from the median calculation. If I can get this function working, it should provide the results I need. Thanks!
Oct 6 '10 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hi Karen

To attach the file. Zip it up and when posting click on the Go Advanced button. Scroll down to Manage Attachments.

Mary
Oct 6 '10 #8
nico5038
3,080 Recognized Expert Specialist
Please attach a sample with the table and the not working report. I've tested the function with your data and all works well.....

Nic;o)
Oct 6 '10 #9
Karen D
7 New Member
Much better - thanks for your help! I've created a subset of relevant files in the attached database. The report I'm having the problem with is Area48Cd. Please let me know if you need anything else. Thanks again!
Attached Files
File Type: zip Area48test.zip (1.14 MB, 120 views)
Oct 6 '10 #10

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

Similar topics

6
4459
by: Jarrod | last post by:
I have multiple reports in one database, on one form. I need to know what reports were run when, and by Network User ID. How do I do that?
2
5444
by: CSDunn | last post by:
Hello, I have an Access 2003 report that opens in print preview and then maximizes upon clicking a button from a form. The OnClick event of the button fires a macro to open the report. How can I use the NoData event of the report to present a message box ( with vbOkayOnly) so that when the button is clicked, if the report returns no data a message box appears, and the report never opens? I've tried the following in code with the...
2
4364
by: BikeToWork | last post by:
I found code online which uses Windows API's to save Access reports to pdf format files. I'm using the full version of Adobe Acrobat Professional 7.0. The problem is that regardless of what I put in the code as a filename it automatically saves the report based on the report name instead of the string passed to the registry key. The code is as follows: '****************************************************************** 'Setting value...
1
1589
by: seawolf | last post by:
Is there a way to create a numbering for the Details in an Access 2003 Report. For instance, if a report has 12 records that make up the Details in a report, can these be numbered, i.e., 1, 2, 3, 4, etc., for each Detail record.
0
2226
by: cbj0517 | last post by:
Hello: I am trying to create a Pivot table in an Access 2003 report. I have SQL that retunrs 6 columns of data, (month_year, units, products_per_unit, gross_sales, price_pe_product, and avg_days_to_fulfill). I would like the columns of the pivot to be the months of the year, and a row for each of the other columns, with a total column at the end. It can be done in Excel, but I need it to be in a report. The crosstab query would be great,...
1
1342
by: klinke1006 | last post by:
Hi, I have written several Access 2003 reports. These reports run properly for some of the users of the Access Application. For others a report that should display on one page displays on many pages. Has anyone experienced this and can you help me solve it? Thanks Sue
5
3356
by: lionelm2007 | last post by:
When I view a report in another machine, it looks slightly different. First of all, the logo in the report heading does not show up when you print, also in print preview, you can see the last letter is missing from several texts. I have read other postings online and have done why they asked to check. I have checked that the printer settings are the same for both machines and the same fonts are installed (ie arial). Both machines are using...
1
2735
by: J360 | last post by:
In Access 2003, I'm creating a dynamic report and am trying to place text boxes into group headers. One report will have 6 group levels. I can place controls in the first two group headers easily by using the acGroupLevel1/2Header option. How do I place in the other group headers? acGroupLevel3Header doesn't appear to exist and manually typing it doesn't seem to work.
1
1200
by: lmyers | last post by:
I am a novice MS Access user. I have created a simple purchase order DB with a simple report that displays the contents of individual POs as they are created. My issue is that I can navigate to the first PO, invoke the report, and see the data - everything is fine. Same for the second PO. But for the third, fourth, and fifth POs (I only have 5 in my test data set), when I navigate to the PO and invoke the report, the report comes up...
2
3625
by: passterelli | last post by:
I have created a report that displays the contents of large memo fields. The report must be exported to MS Word (or .rtf) so the type style and type size can be modified according to the final user's preferences. The report doesn't export as expected. When the exported .rtf file is opened in MS Word, the layout appears as it does on the report in MS Access. However, at the end of each line, there is a carriage return. Considering that each...
0
8984
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
8823
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
9363
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...
1
9312
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
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...
0
8237
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
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
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
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.