Median Time
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Median Time
I need to report the Median Time for each staff member. Could you please tell me how to tweak the module from Post=106449? That post has helped me with many reports but unfortunately the TAT (turn around time) on the original was for the whole department and not each individual.
-
- Administrator
- Posts: 78627
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Median Time
If staff members are identified by a number field, say StaffID, you can use
=DMedian("TAT","mktblMedian","StaffID=" & [StaffID])
If they are identified by a text field, say StaffName, you can use
=DMedian("TAT","mktblMedian","StaffID=" & Chr(34) & [StaffID] & Chr(34))
Chr(34) is the double quote character ", used to enclose string values.
=DMedian("TAT","mktblMedian","StaffID=" & [StaffID])
If they are identified by a text field, say StaffName, you can use
=DMedian("TAT","mktblMedian","StaffID=" & Chr(34) & [StaffID] & Chr(34))
Chr(34) is the double quote character ", used to enclose string values.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
Thank you Hans!
I'm getting a debug error on: Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
I'm getting a debug error on: Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
I'm getting a debug error on: Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
-
- Administrator
- Posts: 78627
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Median Time
Have you set a reference to the Microsoft DAO 3.6 Object Library if you have a .mdb file, or to the Microsoft Office n.0 Access database engine Object Library if you have a .adddb file?
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
If I only understood that. lol
This is the module that I pasted in. Is it somewhere in here?
Function DMedian(FieldName As String, TableName As String, Optional WhereCondition As String)
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim arr
Dim m As Long
Set dbs = CurrentDb
strSQL = "SELECT [" & FieldName & "] FROM [" & TableName & "]"
If WhereCondition <> "" Then
strSQL = strSQL & " WHERE " & WhereCondition
End If
strSQL = strSQL & " ORDER BY [" & FieldName & "]"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
arr = rst.GetRows(1000000) ' fetch at most 1,000,000 records
rst.Close
Set rst = Nothing
Set dbs = Nothing
m = UBound(arr, 2)
If m Mod 2 = 0 Then
DMedian = arr(0, m / 2)
Else
DMedian = (arr(0, (m + 1) / 2) + arr(0, (m - 1) / 2)) / 2
End If
End Function
This is the module that I pasted in. Is it somewhere in here?
Function DMedian(FieldName As String, TableName As String, Optional WhereCondition As String)
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim arr
Dim m As Long
Set dbs = CurrentDb
strSQL = "SELECT [" & FieldName & "] FROM [" & TableName & "]"
If WhereCondition <> "" Then
strSQL = strSQL & " WHERE " & WhereCondition
End If
strSQL = strSQL & " ORDER BY [" & FieldName & "]"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
arr = rst.GetRows(1000000) ' fetch at most 1,000,000 records
rst.Close
Set rst = Nothing
Set dbs = Nothing
m = UBound(arr, 2)
If m Mod 2 = 0 Then
DMedian = arr(0, m / 2)
Else
DMedian = (arr(0, (m + 1) / 2) + arr(0, (m - 1) / 2)) / 2
End If
End Function
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Median Time
You need to activate a reference to a specific Library file under Tools, References in Access VBA.
See images...
The reference in my screenshot is 15.0. (Office 2013), yours might be 14.0 or 12.0, etc... based on your Office Version
See images...
The reference in my screenshot is 15.0. (Office 2013), yours might be 14.0 or 12.0, etc... based on your Office Version
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
Hopefully my screen shot will show up.
I went into the properties of the database and it says that the Type of file is Microsoft Access Database (.accdb) Should I still click the Microsoft DAO 3.6 Object Library box? I don't see the MISSING: Utility.mda or the Microsoft Visual Basic for Applications Extensiblity... from the other screen shot. Does that matter?
I went into the properties of the database and it says that the Type of file is Microsoft Access Database (.accdb) Should I still click the Microsoft DAO 3.6 Object Library box? I don't see the MISSING: Utility.mda or the Microsoft Visual Basic for Applications Extensiblity... from the other screen shot. Does that matter?
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78627
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Median Time
Thanks - your screenshot looks fine, and it contains the correct references.
Does mktblMedian contain a field StaffID?
Does mktblMedian contain a field StaffID?
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78627
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
I removed the text box yesterday because it was locking up and the yellow highlight was on: Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
I'm sorry, I must have done something wrong yesterday because today, the yellow highligh is on: arr = rst.GetRows(1000000) ' fetch at most 1,000,000 records
It still isn't working but different text is being highlighted today.
I'm sorry, I must have done something wrong yesterday because today, the yellow highligh is on: arr = rst.GetRows(1000000) ' fetch at most 1,000,000 records
It still isn't working but different text is being highlighted today.
-
- Administrator
- Posts: 78627
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
The debug yellow highlight is on: arr = rst.GetRows(1000000) ' fetch at most 1,000,000 records
mktblMedian has 728 records with 12 staff members.
TAT is a Date/Time field formatted as Short Time.
StaffID is text.
mktblMedian has 728 records with 12 staff members.
TAT is a Date/Time field formatted as Short Time.
StaffID is text.
-
- Administrator
- Posts: 78627
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
This is the only message that I see:
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78627
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
I think I've found it. Is this what you need?
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78627
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 2StarLounger
- Posts: 110
- Joined: 08 Mar 2011, 13:18
Re: Median Time
I was creating the zip file and while stripping the db down I realized that some of the appointments weren't assigned so [StaffID] had blanks. I deleted the blanks and the error went away. Whew! I'm glad that's fixed. I apologize for taking up so much of your time! Thank you for hanging in there with me!!!