RE: Help with a function using recordsets
- From: "kkmcg" <kkmcg@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Jun 2005 11:45:05 -0700
Hey Jonathan,
I see a couple of things that might be causing problems.
1) Syntax error in SQL statement:
strsql = strsql & "WHERE[" & Age & "] IS NOT NULL "
--- Seems minor but there needs to be a space between 'Where' and '['
--- Should be
strsql = strsql & "WHERE [" & Age & "] IS NOT NULL "
2) This may actually be correct based on your fields in the tables but
it looks like you are passing in the names of the fields i.e.
strsql = "select [" & Age & "],[" & Reading_Number & "] FROM [" & tblAges
& "]
it looks like the value contained in Age is the name of a field in a table
whose name is contained in the variable tblAges, same with Reading_number.
If the name of the field is Age and you are actually trying to determine if
the value in the field Age matches the value in the variable age then you
need to change your SQL statement
If this doesn't help post back and we'll go from there
Ken
"Jonathan Snyder via AccessMonster.com" wrote:
> 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
>
> --
> Message posted via http://www.accessmonster.com
>
.
- Follow-Ups:
- RE: Help with a function using recordsets
- From: Jonathan Snyder via AccessMonster.com
- RE: Help with a function using recordsets
- References:
- Help with a function using recordsets
- From: Jonathan Snyder via AccessMonster.com
- Help with a function using recordsets
- Prev by Date: Re: Desperately need help with Array!
- Next by Date: RE: Create New Database
- Previous by thread: Help with a function using recordsets
- Next by thread: RE: Help with a function using recordsets
- Index(es):
Relevant Pages
|