473,396 Members | 1,895 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,396 software developers and data experts.

Use custom function filtered information

I am using a custom fuction (I got the information from Microsofts site for the code)

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

=Median("<TableName>", "<FieldName>")

My problem is that within my db there are only 2 fields, [gdate] and [reading]

gdate = date the reading was taken
reading = actual reading taken

I need the database to derive the median from the month the reading was taken without considereing the day or year that the reading was taken (i have readings from the last 120 years)

When i filter the data (by right clicking and choosing one of the automatic date filters to filter by month) the median doesnt change because it is choosing the median from the entire table.

Does anybody know how to get the median () fuction to work on the filtered data, and not the whole table. If i have to i know that i could just create 12 tables, but i was hoping not to do that.
Oct 5 '08 #1
4 1215
ADezii
8,834 Expert 8TB
I'm a little confused as to exactly what you are requesting - kindly post some sample data, along with what the desired results should be.
Oct 5 '08 #2
NeoPa
32,556 Expert Mod 16PB
On your form, is there a current record showing, from whose date (month) you want the Median function to calculate a result?
Oct 5 '08 #3
NeoPa
32,556 Expert Mod 16PB
If so, and I guess there must be, you could pass the date value (by referring to the control on the form where this is shown) to the Median() function.

The Median() function code itself would need to be changed to accept and process the date data such that the relevant result is produced. Let me know if this makes sense or whether more explanation is needed.

PS. Congratulations to ADezii on 4,000 posts. Please visit the Milestones Forum ;)
Oct 5 '08 #4
ADezii
8,834 Expert 8TB
If so, and I guess there must be, you could pass the date value (by referring to the control on the form where this is shown) to the Median() function.

The Median() function code itself would need to be changed to accept and process the date data such that the relevant result is produced. Let me know if this makes sense or whether more explanation is needed.

PS. Congratulations to ADezii on 4,000 posts. Please visit the Milestones Forum ;)
Thanks NeoPa, right on your tail!
Oct 5 '08 #5

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

Similar topics

1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
3
by: dbaxter7 | last post by:
OK, here's my dilemma. I am trying to create a system to track cases and clients. There are instances when cases have multiple clients, and there are instances where clients have multiple cases. ...
7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
0
by: RyanG | last post by:
when the value that determines the filter is databound?? I am trying to make a DropDownList for a set of data that I use a lot throughout my project. So I extended the DropDownList to retrieve...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
6
by: Buddy Ackerman | last post by:
When trapping unhandled errors in a web page via the Page_Error or Application_Error event procedures is it possible to get the line number on which the error occured? When not using custom error...
2
by: TD | last post by:
I've read several posts here that say global variables are reset whenever an unhandled error occurs. I want to use a custom form property instead of a global variable to store a boolean value. My...
0
by: ChopStickr | last post by:
I have a custom control that is embedded (using the object tag) in an html document. The control takes a path to a local client ini file. Reads the file. Executes the program specified in...
6
by: Nettle | last post by:
Purpose: I am creating a mailing distribution list database. Users should be able to filter/search contacts and add them to distribution lists they have created. My problem? I can't add multiple,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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,...

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.