The database is set up with Mission and within each mission are sets. Each set contains aproxmently 150 records that date/time temp, depth. I want to find the median for both temp and depth for each set. I have used the function provided by the MS Access support page but it calculates the median for the whole data base not each set. How would I get it to sort the data before finding the median.
thanks
-Eric
7 1410 NeoPa 32,556
Expert Mod 16PB
Not very clear Eric (You should fix the typos before posting). What function are you using? What SQL have you tried?
I would expect you would need to GROUP BY whatever the sets are, but you haven't explained that properly so I have very little to work with.
I'm sure if you take the time to present the question fully and without errors we can help you to a solution.
Ok thanks
The database is of depth and temperature records.
The columns are named
Mission, Set#, DateAndTime, Temp, Depth
Each Mission contains many sets. Each set contains about 150 different records from every 12 seconds between the start and end time. I have created a module with the code from the MS Access help page… - Function Median(tName As String, fldName As String) As Single
-
Dim MedianDB As DAO.Database
-
Dim ssMedian As DAO.Recordset
-
Dim RCount As Integer, i As Integer, x As Double, y As Double, _
-
OffSet As Integer
-
Set MedianDB = CurrentDb()
-
Set ssMedian = MedianDB.OpenRecordset("SELECT [" & fldName & _
-
"] FROM [" & tName & "] WHERE [" & fldName & _
-
"] IS NOT NULL ORDER BY [" & fldName & "];")
-
ssMedian.MoveLast
-
RCount% = ssMedian.RecordCount
-
x = RCount Mod 2
-
If x <> 0 Then
-
OffSet = ((RCount + 1) / 2) - 2
-
For i% = 0 To OffSet
-
ssMedian.MovePrevious
-
Next i
-
Median = ssMedian(fldName)
-
Else
-
OffSet = (RCount / 2) - 2
-
For i = 0 To OffSet
-
ssMedian.MovePrevious
-
Next i
-
x = ssMedian(fldName)
-
ssMedian.MovePrevious
-
y = ssMedian(fldName)
-
Median = (x + y) / 2
-
End If
-
If Not ssMedian Is Nothing Then
-
ssMedian.Close
-
Set ssMedian = Nothing
-
End If
-
Set MedianDB = Nothing
-
End Function
When I run this it gives me the median of the either database. I was hoping to be able to create a module that would allow me to find the median of each set.
The basic principle is to modify your SQL statement within the function.
You would need to make 2 modifications to your described function. First make room in the function calling to accept the Set Nr, and mission NR (assuming its a nr) - Function Median(tName As String, fldName As String,lngMissionNr as long, lngSetNr as long) As Single
Then modify the SQL's where clause. - SELECT [" & fldName & "]" & _
-
" FROM [" & tName & "] " & _
-
" WHERE [" & fldName & "] IS NOT NULL " & _
-
" AND Mission=" & lngMissionNr & _
-
" AND [SET#]=" & lngSetNr & _
-
"ORDER BY [" & fldName & "];"
Wouldn't you have to GROUP BY Mission and Set#, then Calculate the Medians for both Temp and Depth?
I tried to use the
[SELECT [" & fldName & "]" & _]
but the module did not like it and marked it as red.
An answer like that gives NOTHING to work forward from. You have not shown HOW you use it, you only post a fraction of the code, so I have no idea whether its because you simply do not grasp the concept, or was to lazy to post it. You enclose it in square brackets which makes no sense to me as a reader. Come back and try again.
NeoPa 32,556
Expert Mod 16PB
I think the confusion here Smiley (and Eric) is that post #4 has code that starts in the middle of a line of VBA. Most of us that do this a lot would probably have recognised that as a simple oversight, but I expect Eric was confused by it and tried to make some sense out of it, but with little experience of the subject failed to see what was going on.
Smiley's code should probably have started something like : - strSQL = "SELECT [" & fldName & "]" & _
-
" FROM [" & tName & "] " & _
-
...
NB. In Access one often has to work with SQL strings, and this gets particularly complicated when creating SQL strings from within VBA code (as in this instance). I hope this clarifies the situation somewhat :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jim west via SQLMonster.com |
last post by:
I have website problems with mySQL data base, I have a website and was told the only way to change my password is within my SQL data base files and that it would be over my head buy the site maker,...
|
by: narasingarao |
last post by:
Hi to group,
I'm a student of M.C.A. from B.I.T. Ranchi...I'm in my project
period here i have to migrate the MS-Access database table to Oracle
data base tables...so, please help me in getting...
|
by: Paul Copeland |
last post by:
Hi,
I am using Access2000 and have developed a data base which successfully uses
DAO code in some of the forms to update tables.
Recently I converted the data base to a split MDE data base and now...
|
by: Vicente Nicolau |
last post by:
Hello
I'm making a PDA project that uses a data base. That data base is saved in a
xml file. When the application starts up, I load the xml file in memory. The
application makes changes in the...
|
by: Lian |
last post by:
Hi every body
I have a problem with accesses and visual studio. I've just installed
XP and I can't get a connection with the Data base. I have this error
and I don't know how to fix it
The...
|
by: AI Man |
last post by:
Greetings,
I have been searching the web and Access relentlessly trying to find a way to call an Access macro from a different Access data base.
Example - The form button gets clicked and the...
|
by: nandhanvijay |
last post by:
hi every
am trying to connect data base in vb.net but am unable to connect. As per the book am following that says to connect to data base go to tools menu connect to data base option. u will...
|
by: joeldault |
last post by:
Question For Microsoft Access Data Base
--------------------------------------------------------------------------------
I am Trying to create a single formula that would do the following:
If...
|
by: apwuhp |
last post by:
We have used a data replication product that has replicated our production data base to another server, both servers are AIX 5.3 operating system and IBM DB2 data bases. The product replicates at the...
|
by: gerryis2000 |
last post by:
Hi, kindly guide me on how to solve this security problem. i set a passord to the data base and seems to work well. but since several people use the data base and know the passord, i think its risky....
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
| |