Return a value from a previous record (1 Viewer)

GaryW

New member
Local time
Today, 18:47
Joined
Oct 29, 2002
Messages
8
if i have a form thats contains a subform, which is in continuous forms view, is there anyway that i can take a value from the previous record and use it in a calculation in the next new record in this subform, ie the subform is used to display and work out continuous calculations, and the total of the previous record is used in calculating the total of the next new record.

hope this makes sense
 
R

Rich

Guest
Function PrevRecValc(KeyName As String, KeyValue, _
FieldNameToGet As String, Source As String)
Dim rs As Recordset

On Error GoTo Err_PrevRecValc

' The default value is zero.
PrevRecValc = 0

' Get the form recordset.
Set rs = CurrentDb().OpenRecordset((Source), dbOpenDynaset)

' Find the current record.
Select Case rs.Fields(KeyName).Type
' Find using numeric data type key value?

Case DB_INTEGER, DB_LONG, DB_CURRENCY, DB_SINGLE, _
DB_DOUBLE, DB_BYTE
rs.FindFirst "[" & KeyName & "] = " & KeyValue
' Find using date data type key value?
Case DB_DATE
rs.FindFirst "[" & KeyName & "] = #" & KeyValue & "#"
' Find using text data type key value?
Case DB_TEXT
rs.FindFirst "[" & KeyName & "] = '" & KeyValue & "'"

Case Else
MsgBox "ERROR: Invalid key field data type!"
Exit Function
End Select

' Move to the previous record.
rs.MovePrevious

' Return the result.
PrevRecValc = rs(FieldNameToGet)

Bye_PrevRecValc:
Exit Function
Err_PrevRecValc:
Resume Bye_PrevRecValc
End Function
 

Users who are viewing this thread

Top Bottom