testdba
Registered User.
- Local time
- Yesterday, 19:36
- Joined
- Dec 16, 2004
- Messages
- 26
I know I know, another Dmax/Dcount question.
I didn't want to ask it, but I just can't figure out why my Dmax/Dcount statement won't increment. Every time the string is combined I get a value of 1 from Dmax/Dcount. I have tried both Dmax and Dcount and I get the same results from them both.
Maybe I don't understand the functions, but I just need it to count up the number of records that have today's date and then add 1 to that number. If the function count's up seven records, then the number needs to be eight. I am on the right track, aren't I?
I really don't even use the INVNumberForDate field (it does have numbers in it though for testing), is it necessary?

Maybe I don't understand the functions, but I just need it to count up the number of records that have today's date and then add 1 to that number. If the function count's up seven records, then the number needs to be eight. I am on the right track, aren't I?
Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
If IsNull(Me!InvoiceNumber) Then
Dim strNextAvailable As String
Dim strINV As String
'Count the number of records for the current date and add 1 to it
strNextAvailable = 1 + Nz(DCount("[INVNumberForDate]", "tblInvoice", "[InvoiceDate] = 'Date'"), 0)
'Format strNextAvailable to have proper number of digits. This gives proper spacing for
'up to 9999 orders in a day
strNextAvailable = Format(strNextAvailable, "0000")
'Combine all to generate unique invoice number based on number of entried for a specific date
strINV = "INV00" & Format(Me.InvoiceDate, "MMDDYY") & strNextAvailable
'put the invoice number in the InvoiceNumber field
Me!InvoiceNumber = strINV
End If
End Sub
I really don't even use the INVNumberForDate field (it does have numbers in it though for testing), is it necessary?