If you can post some data in excel of access that would help. These functions were designed to return the value of the percentile for the field in question. You seem to want to return a record that is at that percentile.
Something like this instead
Public Function DPercentileRecord(IDfield As String, Expr As String, Domain As String, ByVal Percentile As Double) As Variant
Dim strSQL As String
Dim N As Integer
Dim N_k As Long
Dim rs As DAO.Recordset
'IDField: Name of the Primary key field or unique ID
'Expr: The Field to sort on
'Domain: The query or table name
'Percentile: The Percentile
strSQL = "SELECT " & IDfield & ", " & Expr & " FROM " & Domain
strSQL = strSQL & " WHERE NOT " & Expr & " IS NULL ORDER BY " & Expr
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
If Not (rs.EOF And rs.BOF) Then
N = rs.RecordCount
N_k = Int((Percentile / 100 * (N - 1)) + 1)
'There are three interpretations of this rank.
'I am going to round up
rs.AbsolutePosition = N_k - 1 '0 based
DPercentileRecord = rs.Fields(IDfield)
You can then make a table with the values 5, 10, 15, .... . Then use that in a query to get the IDs for the the percentile records
Select PercentileNumber, DpercentileRecord("ID","Depth","TblGWMeasurement") AS MeasuermentID from TblPercentile
Now join qryPecentileIDs to tblGWMeasurement to show the related information for each percentile.
Now I am not sure if this is totally correct. There are a couple interpretations on the percentile. When the rank comes out to a integer this is OK, but what to do when it is not. Assume you have 11 records and want the 50th percentile. Then it is the six record because there are 5 below and 5 records above the 6th record. But if you have ten records you find the average value of the 5th and 6th record to get a value, but you want a record. So which one do you want, the 5th or sixth. I rounded up, or you could straight round.