473,811 Members | 3,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use custom function filtered information

31 New Member
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("<Table Name>", "<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 1235
ADezii
8,834 Recognized Expert Expert
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,579 Recognized Expert Moderator MVP
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,579 Recognized Expert Moderator MVP
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 Recognized Expert Expert
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
3555
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 modular and work across forms and sub-forms. My previous code was taken from the Access Expert Solutions 97 (Leszynski) many years ago. As my database became more complex with multiple sub-forms and intricate combo boxes, the code faltered. Some...
3
1686
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. I have several tables to house all the information, but the three that connect the dots are tblClients tblCases tblCaseClients
7
4758
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 and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that...
0
2519
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 from the database a set of data to populate the itself with. Now to make this control as reusable as possible I also added a new property to this Custom DropDownList. With the goal being that this property would be used with the DataView...
8
7840
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 VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle "http://msdn.microsoft.com/library/default.asp?url=/library/en-...
6
1318
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 pages the default error page displays the line number that the error occured on. Since this page is not displayed I have no idea what the error actually is. The stack trace usually isn't very helpful in determining what line caused the error so...
2
2299
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 question is does a custom form property get reset also? Was also wondering if there is any reason one would ever use a global variable since the consensus seems to be to never use global variables?
0
1980
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 the ini on the client's PC. After the program has ended the control looks in a client side temp folder (specified by the ini file) for an image created by the executed program. If the image is there, then the control moves the file to a public folder...
6
1960
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, filtered contacts to the proper distribution list. I have two main forms, described below. These forms are based on three tables. Tables tbl_MainContact: Holds all contact information tbl_JoinContactToDistributionList: A join table
0
9605
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
10651
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
10393
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
10405
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
6893
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
5556
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
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
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
3020
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.