Hi There!
I have a question. I have a table, tblMeterReading with the following fields...
ReadingID
ReadingDate
ContractID
BillingNumber
Reading
I use this code to assign sequential values to BillingNumber per ContractID...
Dim L As Long
If IsNull(ReadingID) Then Exit Sub
L = DCount("ReadingID", "tblMeterReading", "ReadingID <>" & [ReadingID] & " And [ContractID] = " & Me.SerialCombo & "")
If L = 0 Then
L = 0
Else
L = L + 1
End If
BillingNo = Year(ReadingDate) & "-" & Format(L, "0000")
This code assigns the sequential number to BillingNumber AfterUpdate of SerialCombo in YYYY-0000 format. The code works fine, but here is the problem...
My plan is just to import a few months data and have the numbering sequence continued from the last number since some of the older Readings can no longer be recovered. Since I am using DCount for this numbering, I cannot have just a few readings for each of the ContractID because that will definitely show a low count which wont match the last number of the sequence.
Example
2023-0001, 2023-0002,......2024-0024
If I record only say 3 previous readings, then the BillingNumber will be assigned as 2025-0004 because the DCount will return a value of only 3.
Is there a way to implement this via DMax instead of DCount?
I tried using DMax, but I get a type mismatch error since I have formatted the BillingNumber as String with the code BillingNo = Year(ReadingDate) & "-" & Format(L, "0000")
Thanks for the time and help!