L
Lonnie
Hey all, noob here---I've been working on this function for several days,
but I'm still getting "Undefinded Function" when running this:
My query field: MEAN: Dmedian("PLASMA PRODUCTION","MINUTES")
(where as Plasma production is the table, minutes is the record set i want to
find the median of)
and my code:
Option Compare Database
Public Function dmedian(Expr As String, Domain As String) As Double
End Function
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Temp As Double
Dim OrderedSQL As String
'construct SQL
OrderedSQL = "SELECT " & Expr
OrderedSQL = OrderedSQL & " FROM " & Domain
If Criteria <> "" Then
OrderedSQL = OrderedSQL & " WHERE " & Criteria
End If
OrderedSQL = OrderedSQL & " ORDER BY " & Expr & ";"
Set db = CurrentDb
Set rs = db.OpenRecordset(OrderedSQL)
rs.MoveLast
NumRecords = rs.RecordCount
rs.MoveFirst
rs.Move Int(NumRecords / 2)
Temp = rs.Fields(Expr)
If NumRecords / 2 = Int(NumRecords / 2) Then
'there is an even number of records
rs.MovePrevious
Temp = Temp + rs.Fields(Expr)
dmedian = Temp / 2
Else
'there is an odd number of records
dmedian = Temp
End If
rs.Close
db.Close
End Function
not real sure what I'm missing, enlightenment is appriciated!
but I'm still getting "Undefinded Function" when running this:
My query field: MEAN: Dmedian("PLASMA PRODUCTION","MINUTES")
(where as Plasma production is the table, minutes is the record set i want to
find the median of)
and my code:
Option Compare Database
Public Function dmedian(Expr As String, Domain As String) As Double
End Function
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Temp As Double
Dim OrderedSQL As String
'construct SQL
OrderedSQL = "SELECT " & Expr
OrderedSQL = OrderedSQL & " FROM " & Domain
If Criteria <> "" Then
OrderedSQL = OrderedSQL & " WHERE " & Criteria
End If
OrderedSQL = OrderedSQL & " ORDER BY " & Expr & ";"
Set db = CurrentDb
Set rs = db.OpenRecordset(OrderedSQL)
rs.MoveLast
NumRecords = rs.RecordCount
rs.MoveFirst
rs.Move Int(NumRecords / 2)
Temp = rs.Fields(Expr)
If NumRecords / 2 = Int(NumRecords / 2) Then
'there is an even number of records
rs.MovePrevious
Temp = Temp + rs.Fields(Expr)
dmedian = Temp / 2
Else
'there is an odd number of records
dmedian = Temp
End If
rs.Close
db.Close
End Function
not real sure what I'm missing, enlightenment is appriciated!