Hi All,
Happy New Year 2016, I'm still newbie here. Here's my story, I have an invoice form, which there's auto increment numbering there using DMAX function for each new record.
for the user, when the form is blank (but there's invoice number in it), when I press "save and exit" button, I want to delete that empty records. so
when i open the form again, it'll automatically load new records with the same last invoice number when i close it.
but I can't get it right, it always returns with 1 number higher than previous, and the last records is blank, is there something wrong with the code?
I'm also attaching the database, the form is under the name "InvoiceF".
example :
1. currently invoice number 32, without any items there >> click "save & close" >> records number 32 = deleted
2. open the form >> automatically create new records >> the invoice number = 32.
here's my code
thanks a lot for the help
cheers
Happy New Year 2016, I'm still newbie here. Here's my story, I have an invoice form, which there's auto increment numbering there using DMAX function for each new record.
for the user, when the form is blank (but there's invoice number in it), when I press "save and exit" button, I want to delete that empty records. so
when i open the form again, it'll automatically load new records with the same last invoice number when i close it.
but I can't get it right, it always returns with 1 number higher than previous, and the last records is blank, is there something wrong with the code?
I'm also attaching the database, the form is under the name "InvoiceF".
example :
1. currently invoice number 32, without any items there >> click "save & close" >> records number 32 = deleted
2. open the form >> automatically create new records >> the invoice number = 32.
here's my code
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'TO INSERT AUTO INCREMENT INVOICE NUMBER
If Me.NewRecord = True Then
Me.InvoiceNumber = Nz(DMax("InvoiceNumber", "InvoiceT") + 1, 1)
End If
End Sub
-------------------------------------------------------------------------------------------------------------------
Private Sub Form_Current()
Me.PaymentMethod.Value = "Cash"
End Sub
-------------------------------------------------------------------------------------------------------------------
Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub
-------------------------------------------------------------------------------------------------------------------
Private Sub SaveExit_Click()
If Me.Total.Value = 0 Or IsNull(Me.TotalBayar) = True Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings (warningsoff)
DoCmd.Close
End If
End Sub
thanks a lot for the help
cheers