Hello,
I currently use the following function in a subform to successfully retrieve the previous record's value (a date):
I am trying to get the same function to work on a report. So I made the following changes:
The calculated control on the report is
And it always returns "apple"
What do I need to change in order to get this working in the report?
I currently use the following function in a subform to successfully retrieve the previous record's value (a date):
Code:
Function GetPreviousValue(frm As Form, strField As String) As Variant
On Error GoTo Err_GetPrevValue
Dim rst As Recordset
Set rst = frm.RecordsetClone
rst.Bookmark = frm.Bookmark
rst.MoveNext
GetPreviousValue = rst(strField)
Exit_GetPrevValue:
Set rst = Nothing
Exit Function
Err_GetPrevValue:
If Err.Number <> 3021& Then
Debug.Print Err.Number, Err.Description
End If
GetPreviousValue = Null
Resume Exit_GetPrevValue
End Function
I am trying to get the same function to work on a report. So I made the following changes:
Code:
Function GetPreviousValue([b]rep As Report[/b], strField As String) As Variant
On Error GoTo Err_GetPrevValue
Dim rst As Recordset
Set rst = [b]rep[/b].RecordsetClone
rst.Bookmark = [b]rep[/b].Bookmark
rst.MoveNext
GetPreviousValue = rst(strField)
Exit_GetPrevValue:
Set rst = Nothing
Exit Function
Err_GetPrevValue:
If Err.Number <> 3021& Then
Debug.Print Err.Number, Err.Description
End If
GetPreviousValue = [b]"apple"[/b] [COLOR="Lime"]'added to be easily recognised[/COLOR]
Resume Exit_GetPrevValue
End Function
The calculated control on the report is
Code:
=GetPreviousValue([Report],"[i]myfieldname[/i]")
What do I need to change in order to get this working in the report?