SOS!
I have a form with the following 3 fields:
1) ID
2) TheDate
3) PreviousDate
I'm trying to put the previous date in the same row with the current date for easier comparison but I've struggled for over a week now.
Please show me what's wrong with this code. I entered
=PrevRecVal(Form,"ID",[ID],"TheDate") in the control source of PreviousDate, but I keep getting #Name? when I switch to Form view.
What am I doing wrong? Please, someone show the proper way with a quick example if possible. Much appreciation and thanks.
Function PrevRecValue(F As Form, ID As String, TheDate As String)
Dim RS As DAO.Recordset
' The default value is zero.
PrevRecValue = 0
' Get the form recordset.
Set RS = Me.RecordsetClone
' Find the current record.
Select Case RS.Fields(TheDate).Type
' Find using numeric data type key value?
Case DB_INTEGER, DB_LONG, DB_CURRENCY, DB_SINGLE, _
DB_DOUBLE, DB_BYTE
RS.FindFirst "[" & ID & "] = " & ID
MsgBox "ERROR: Invalid key field data type!"
Exit Function
End Select
' Move to the previous record.
RS.MovePrevious
' Return the result.
PrevRecValue = RS(TheDate)
End Function
I have a form with the following 3 fields:
1) ID
2) TheDate
3) PreviousDate
I'm trying to put the previous date in the same row with the current date for easier comparison but I've struggled for over a week now.
Please show me what's wrong with this code. I entered
=PrevRecVal(Form,"ID",[ID],"TheDate") in the control source of PreviousDate, but I keep getting #Name? when I switch to Form view.
What am I doing wrong? Please, someone show the proper way with a quick example if possible. Much appreciation and thanks.
Function PrevRecValue(F As Form, ID As String, TheDate As String)
Dim RS As DAO.Recordset
' The default value is zero.
PrevRecValue = 0
' Get the form recordset.
Set RS = Me.RecordsetClone
' Find the current record.
Select Case RS.Fields(TheDate).Type
' Find using numeric data type key value?
Case DB_INTEGER, DB_LONG, DB_CURRENCY, DB_SINGLE, _
DB_DOUBLE, DB_BYTE
RS.FindFirst "[" & ID & "] = " & ID
MsgBox "ERROR: Invalid key field data type!"
Exit Function
End Select
' Move to the previous record.
RS.MovePrevious
' Return the result.
PrevRecValue = RS(TheDate)
End Function
Last edited: