I am using below function to create row number field, it works fine unless I run the query more than once. For instance if you run the query and there are 30 rows, the next time you run the query or just filter it, it starts with 31.
Public StoredRowNumber As Variant
Function Rownumber(TheField) As Integer
If OldlastField = TheField Then
Else: ResetRowNum
End If
StoredRowNumber = StoredRowNumber + 1
Rownumber = StoredRowNumber
OldlastField = TheField
End Function
Function GetRowNum(TheField) As Integer
GetRowNum = StoredRowNumber
End Function
Function ResetRowNum()
StoredRowNumber = 0
End Function
What I expect is that the function to count from 1 every time the query is run.
Could anyone help with that?
Thanks.