Percentile and parameter (1 Viewer)

Tlandry

New member
Local time
Today, 07:28
Joined
Dec 10, 2017
Messages
3
Would anyone happen to know how to modify this VBA code to take into account an underlying date between parameter in the waittime query it will be referencing?
[ENTER START DATE mm/dd/yyyy:]"[ENTER END DATE mm/dd/yyyy:]",


Public Function PercentileRst(RstName As String, DAYS_DFF As String, PercentileValue As Double) As Double
'This function will calculate the percentile of a recordset.
'The field must be a number value and the percentile has to
'be between 0 and 1.
If PercentileValue < 0 Or PercentileValue > 1 Then
MsgBox "Percentile must be between 0 and 1", vbOKOnly
End If
Dim PercentileTemp As Double
Dim dbs As Database
Set dbs = CurrentDb
Dim xVal As Double
Dim iRec As Long
Dim i As Long
Dim RstOrig As Recordset
Set RstOrig = CurrentDb.OpenRecordset(RstName, dbOpenDynaset)
RstOrig.Sort = DAYS_DFF
Dim RstSorted As Recordset
Set RstSorted = RstOrig.OpenRecordset()
RstSorted.MoveLast
RstSorted.MoveFirst
xVal = ((RstSorted.RecordCount - 1) * PercentileValue) + 1
'x now contains the record number we are looking for.
'Note x may not be whole number
iRec = Int(xVal)
xVal = xVal - iRec
'i now contains first record to look at and
'x contains diff to next record
RstSorted.Move iRec - 1
PercentileTemp = RstSorted(DAYS_DFF)
If xVal > 0 Then
RstSorted.MoveNext
PercentileTemp = ((RstSorted(DAYS_DFF) - PercentileTemp) * xVal) + PercentileTemp
End If
RstSorted.Close
RstOrig.Close
Set RstSorted = Nothing
Set RstOrig = Nothing
Set dbs = Nothing
PercentileRst = PercentileTemp
End Function

Private Sub test()
MsgBox PercentileRst("waittime", "DAYS_DFF", 0.9)
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:28
Joined
May 7, 2009
Messages
19,237
DAYS_DFF on the code is the
name of Field or Column in your
Query that you wish your Query
to be Sorted.
 

Tlandry

New member
Local time
Today, 07:28
Joined
Dec 10, 2017
Messages
3
Thank you arnelgp, however I am not having any issues with the DAYS_DFF.

My VBA code does not run on queries that have a parameter. My waittime query referenced has a parameter for FIT_PROCESS_DATE where there is a between date promp [ENTER START DATE mm/dd/yyyy:]"[ENTER END DATE mm/dd/yyyy:]".

I would like my VBA code to work with the underlying waittime parameter query.
 

Users who are viewing this thread

Top Bottom