Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Assistance Fixing Code in Module to work with Access 2010

3 views
Skip to first unread message

B Wesenberg

unread,
Nov 22, 2010, 11:33:05 AM11/22/10
to
Good Morning,
I am hoping that someone can assist me with a code problem.
Here is the history of the issue. We had a database that was created
in Access 2003 the database had a module in it called Median:

Public Function MedianOfRst(RstName As String, Company_T As String,
Company_V As String, State_T As String, State_V As String, Group_T As
String, Group_V As String, Sub_Group_T As String, Sub_Group_V As
String, Band_T As String, Amount_T As String) As Double
'This function will calculate the median of a recordset. The
field must be a number value.
Dim MedianTemp As Double
Dim RstOrig As Recordset
Set RstOrig = CurrentDb.OpenRecordset(RstName, dbOpenDynaset)
RstOrig.Sort = Amount_T
RstOrig.Filter = "[" & Company_T & "] = '" & Company_V & "' And
[" & State_T & "] = '" & State_V & "' And [" & Group_T & "] = '" &
Group_V & "' And [" & Sub_Group_T & "] = '" & Sub_Group_V & "' And ["
& Band_T & "] > 'A'"
Dim RstSorted As Recordset
Set RstSorted = RstOrig.OpenRecordset
If RstSorted.RecordCount <> 0 Then
If RstSorted.RecordCount Mod 2 = 0 Then
RstSorted.AbsolutePosition = (RstSorted.RecordCount / 2)
- 1
MedianTemp = RstSorted.Fields(Amount_T).Value
RstSorted.MoveNext
MedianTemp = MedianTemp +
RstSorted.Fields(Amount_T).Value
MedianTemp = MedianTemp / 2
Else
RstSorted.AbsolutePosition = (RstSorted.RecordCount -
1) / 2
MedianTemp = RstSorted.Fields(Amount_T).Value
End If
Else
MedianTemp = 0
End If
MedianOfRst = MedianTemp
End Function


Since the creation of this database we have converted the database to
the new file format (accdb) and are now running office 2010. It seems
to have stopped working once we went to office 2010.

When we run the module it stops on the line of code:
Set RstSorted = RstOrig.openRecordset

We did a little research and found that office 2010 no longer supports
this code. Can anyone help me to re write this code so we can fix the
database?

Thank in advance for any help you can give me.

bwesenberg

Arvin Meyer

unread,
Dec 11, 2010, 7:01:15 PM12/11/10
to
Try changing:

Dim RstOrig As Recordset

to:

Dim RstOrig As DAO.Recordset

and make sure that you have a reference set to DAO.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access
Co-author: "Access Solutions", published by Wiley


"B Wesenberg" <2rs...@gmail.com> wrote in message
news:0677b198-e8d5-4169...@d8g2000yqf.googlegroups.com...

0 new messages