Hi all,
I have invoice form with invoice number generated from Dmax function, when I click exit form, i want the record deleted if there's nothing in the form, so it will keep showing the same number when the form loaded again. here's the code
Code:
Private Sub Form_Current()
'TO MAKE AUTO INCREMENT INVOICE NUMBER WHEN CREATE NEW RECORD
If Me.NewRecord = True Then
'auto increment invoicenumber
Me.InvoiceNumber = Nz(DMax("InvoiceNumber", "InvoiceT") + 1, 1)
End If
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Form_Load()
'TO AUTO CREATE NEW RECORD WHEN FORM IS LOADED
DoCmd.GoToRecord , , acNewRec
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub SaveExit_Click()
'TO DELETE THE RECORD IF THE TOTAL.VALUE (TEXTBOX) =0
If Me.Total.Value = 0 Or IsNull(Me.TotalBayar) = True Or IsNull(Me.PaymentMethod) = True Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close
End If
End Sub
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub NewTransaction_Click()
'TO PREVENT CREATE NEW TRANSACTION IF THERE'S NO ITEMS INPUTTED ON THE CURRENT RECORD
If Me.Total.Value = 0 Or IsNull(Me.TotalBayar) = True Or IsNull(Me.PaymentMethod) = True Then
MsgBox "Masukkan Product / Pembayaran / Total Bayar dahulu"
Else
DoCmd.GoToRecord , , acNewRec
End If
End Sub
the Problem is this code keep generating new invoice number, when it has been deleted. and then close. below is the screenshots
after press "Save & exit button" / "Simpan & keluar", it prompt warning message
when you see at the record, number 5 still generated, and when the form load again, it will become 6.
any clue about what's wrong here? also how to just delete it without prompt any warning message?
thanks a lot for the code
Have nice Monday