J
Jonathan Snyder via AccessMonster.com
I have written a function that I am calling from a query to calculate what I
call a "precision index" (PI). I have recordsets of different sizes, but I
only want to calculate a PI on recordsets with a record count of 3.
I have tried inserting code to the effect of:
if Recordcount <> 3 then
P=0
..nextrecordset
But I get the error message "operation is not supported for this type of
object"
My function is as follows:
'function to calculate precision index on tooth ages by sample_ID and Reader
Function P(Age As String, Reading_Number As String, tblAges As String,
Optional WhereClause As String = "" _
) As Single
Dim dbPI As DAO.Database
Dim rsPI As DAO.Recordset
Dim strsql As String
Dim rcount As String
Dim firstage As String
Dim secondage As String
Dim thirdage As String
Dim PI As Double
Set dbPI = CurrentDb()
strsql = "select [" & Age & "],[" & Reading_Number & "] FROM [" & tblAges & "]
"
strsql = strsql & "WHERE[" & Age & "] IS NOT NULL "
If Len(WhereClause) > 0 Then
strsql = strsql & "AND (" & WhereClause & ") "
End If
strsql = strsql & "ORDER BY [" & Reading_Number & "]"
Set rsPI = dbPI.OpenRecordset(strsql)
If rsPI.EOF = False Then
rsPI.MoveLast
End If
rcount = rsPI.RecordCount
If rcount <> 3 Then
rsPI.NextRecordset
End If
rsPI.FindFirst (Reading_Number = "1")
firstage = rsPI("age")
rsPI.MoveNext
secondage = rsPI("age")
rsPI.MoveNext
thirdage = rsPI("age")
If firstage = secondage And secondage = thirdage Then
P = 1
ElseIf firstage = secondage And secondage <> thirdage Or firstage <>
secondage _
And secondage = thirdage Or firstage = thirdage Then
P = 2
ElseIf firstage <> secondage And secondage <> thirdage Then
P = 3
End If
End Function
If the record count is <> 3 I would like to set P = 0 and move to the next
recordset. If the record count = 3 I would like to calculate a PI based on
the rules defined.
Any suggestions would be appreciated.
Any suggestions
call a "precision index" (PI). I have recordsets of different sizes, but I
only want to calculate a PI on recordsets with a record count of 3.
I have tried inserting code to the effect of:
if Recordcount <> 3 then
P=0
..nextrecordset
But I get the error message "operation is not supported for this type of
object"
My function is as follows:
'function to calculate precision index on tooth ages by sample_ID and Reader
Function P(Age As String, Reading_Number As String, tblAges As String,
Optional WhereClause As String = "" _
) As Single
Dim dbPI As DAO.Database
Dim rsPI As DAO.Recordset
Dim strsql As String
Dim rcount As String
Dim firstage As String
Dim secondage As String
Dim thirdage As String
Dim PI As Double
Set dbPI = CurrentDb()
strsql = "select [" & Age & "],[" & Reading_Number & "] FROM [" & tblAges & "]
"
strsql = strsql & "WHERE[" & Age & "] IS NOT NULL "
If Len(WhereClause) > 0 Then
strsql = strsql & "AND (" & WhereClause & ") "
End If
strsql = strsql & "ORDER BY [" & Reading_Number & "]"
Set rsPI = dbPI.OpenRecordset(strsql)
If rsPI.EOF = False Then
rsPI.MoveLast
End If
rcount = rsPI.RecordCount
If rcount <> 3 Then
rsPI.NextRecordset
End If
rsPI.FindFirst (Reading_Number = "1")
firstage = rsPI("age")
rsPI.MoveNext
secondage = rsPI("age")
rsPI.MoveNext
thirdage = rsPI("age")
If firstage = secondage And secondage = thirdage Then
P = 1
ElseIf firstage = secondage And secondage <> thirdage Or firstage <>
secondage _
And secondage = thirdage Or firstage = thirdage Then
P = 2
ElseIf firstage <> secondage And secondage <> thirdage Then
P = 3
End If
End Function
If the record count is <> 3 I would like to set P = 0 and move to the next
recordset. If the record count = 3 I would like to calculate a PI based on
the rules defined.
Any suggestions would be appreciated.
Any suggestions