zelarra821
Registered User.
- Local time
- Today, 17:54
- Joined
- Jan 14, 2019
- Messages
- 803
Let's see, I'm trying to adapt a function that I had made for a form to find the value of the previous record in a query, and it gives me the syntax error that an operator is missing in "Id <" & Id:
What I want to get is the following:
Feb 5, 2020 5.6 -> null
May 8, 2020 7.5 -> 1.9
Jul 6, 2020 6.5 -> -1
The field to subtract is "Price". I have to use the replace because it has commas. And what fails is the criteria.
As I said before, this way of doing it should work because I have it adapted for a form.
What am I doing wrong?
Greetings.
Code:
Public Function Diferencia(CampoARestar As String) As Variant
Dim regAnterior As Variant
If IsNull(CampoARestar) Then Exit Function
regAnterior = Nz(DMax(Replace(CampoARestar, ",", "."), "TPrecio", "Id<" & Id), 0)
If regAnterior = 0 Then
Diferencia = regAnterior
Else
Diferencia = CampoARestar - regAnterior
End If
End Function
What I want to get is the following:
Feb 5, 2020 5.6 -> null
May 8, 2020 7.5 -> 1.9
Jul 6, 2020 6.5 -> -1
The field to subtract is "Price". I have to use the replace because it has commas. And what fails is the criteria.
As I said before, this way of doing it should work because I have it adapted for a form.
What am I doing wrong?
Greetings.