C
c8tz
HI,
The following is a sub function of the functions used in our research
db. Am encountering an error in my second recordset - called
MARKSTRING.
COUNTSTRING seems to work fine on its own but once markstring is added
- it gives an error in the result.
Need help - my access skills have reached its peaks - the code was set
up by another person who has left.
Could it be possible to break up the code into 3 sep functions? hope
someone can see the loop in this...
Thanks,
CC
***
Function AnnFrondProd(Trial, Plot)
If IsNull(Trial) Or IsNull(Plot) Then
Exit Function
End If
Dim db As Database
Dim rst As Recordset
Dim countstring As String
Dim markstring As String
Dim Countdate As Date, DATE1 As Date, DATE2 As Date
Dim Pos1 As Integer, Pos2 As Integer
Dim cfrondprod As Single
Set db = CurrentDb
countstring = "SELECT TOP 1 FrondCount.CDate, FrondCount.Trial,
FrondCount.Plot, Count(FrondCount.Palm) AS NoOfPalms,
Avg(FrondCount.FrondCount) AS FrondCount, Avg([Pos3]-[pos1]) AS
ProdCount FROM FrondCount GROUP BY FrondCount.CDate, FrondCount.Trial,
FrondCount.Plot HAVING (((FrondCount.Trial) = " & Trial & ") And
((FrondCount.Plot) = " & Plot & ")) ORDER BY FrondCount.CDate DESC;"
Set rst = db.OpenRecordset(countstring)
If rst.BOF Then Exit Function
cfrondprod = rst!prodcount
Countdate = rst!CDate
markstring = "SELECT TOP 3 Date, Colour, Trial, Plot FROM
FrondMarking WHERE Trial = " & Trial & " And Plot = " & Plot & " AND
Date < Datevalue('" & Countdate & "') ORDER BY Date DESC;"
Set db = CurrentDb
'get last 3 marks before last count record
Set rst = db.OpenRecordset(markstring)
If Not rst.BOF Then
rst.MoveFirst
DATE1 = rst!Date
rst.MoveNext
If rst.EOF Then 'Not enough marks
Exit Function
Else
rst.MoveNext
If Not rst.EOF Then
DATE2 = rst!Date
End If
End If
End If
AnnFrondProd = cfrondprod * 365 / (DATE1 - DATE2)
Debug.Print cfrondprod, DATE1; DATE2
End Function
The following is a sub function of the functions used in our research
db. Am encountering an error in my second recordset - called
MARKSTRING.
COUNTSTRING seems to work fine on its own but once markstring is added
- it gives an error in the result.
Need help - my access skills have reached its peaks - the code was set
up by another person who has left.
Could it be possible to break up the code into 3 sep functions? hope
someone can see the loop in this...
Thanks,
CC
***
Function AnnFrondProd(Trial, Plot)
If IsNull(Trial) Or IsNull(Plot) Then
Exit Function
End If
Dim db As Database
Dim rst As Recordset
Dim countstring As String
Dim markstring As String
Dim Countdate As Date, DATE1 As Date, DATE2 As Date
Dim Pos1 As Integer, Pos2 As Integer
Dim cfrondprod As Single
Set db = CurrentDb
countstring = "SELECT TOP 1 FrondCount.CDate, FrondCount.Trial,
FrondCount.Plot, Count(FrondCount.Palm) AS NoOfPalms,
Avg(FrondCount.FrondCount) AS FrondCount, Avg([Pos3]-[pos1]) AS
ProdCount FROM FrondCount GROUP BY FrondCount.CDate, FrondCount.Trial,
FrondCount.Plot HAVING (((FrondCount.Trial) = " & Trial & ") And
((FrondCount.Plot) = " & Plot & ")) ORDER BY FrondCount.CDate DESC;"
Set rst = db.OpenRecordset(countstring)
If rst.BOF Then Exit Function
cfrondprod = rst!prodcount
Countdate = rst!CDate
markstring = "SELECT TOP 3 Date, Colour, Trial, Plot FROM
FrondMarking WHERE Trial = " & Trial & " And Plot = " & Plot & " AND
Date < Datevalue('" & Countdate & "') ORDER BY Date DESC;"
Set db = CurrentDb
'get last 3 marks before last count record
Set rst = db.OpenRecordset(markstring)
If Not rst.BOF Then
rst.MoveFirst
DATE1 = rst!Date
rst.MoveNext
If rst.EOF Then 'Not enough marks
Exit Function
Else
rst.MoveNext
If Not rst.EOF Then
DATE2 = rst!Date
End If
End If
End If
AnnFrondProd = cfrondprod * 365 / (DATE1 - DATE2)
Debug.Print cfrondprod, DATE1; DATE2
End Function