Results 1 to 5 of 5
  1. #1
    radian89 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Dec 2015
    Posts
    37

    Delete Blank Record When Exit Form (won't work)

    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
    Click image for larger version. 

Name:	InvoiceNum.JPG 
Views:	14 
Size:	42.8 KB 
ID:	23249
    after press "Save & exit button" / "Simpan & keluar", it prompt warning message
    Click image for larger version. 

Name:	InvoiceNum2.JPG 
Views:	12 
Size:	28.3 KB 
ID:	23250
    when you see at the record, number 5 still generated, and when the form load again, it will become 6.
    Click image for larger version. 

Name:	InvoiceNum3.JPG 
Views:	12 
Size:	30.5 KB 
ID:	23251

    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

  2. #2
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106

    A better way might be to put ...

    Quote Originally Posted by radian89 View Post
    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
    Click image for larger version. 

Name:	InvoiceNum.JPG 
Views:	14 
Size:	42.8 KB 
ID:	23249
    after press "Save & exit button" / "Simpan & keluar", it prompt warning message
    Click image for larger version. 

Name:	InvoiceNum2.JPG 
Views:	12 
Size:	28.3 KB 
ID:	23250
    when you see at the record, number 5 still generated, and when the form load again, it will become 6.
    Click image for larger version. 

Name:	InvoiceNum3.JPG 
Views:	12 
Size:	30.5 KB 
ID:	23251

    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


    this Me.InvoiceNumber = Nz(DMax("InvoiceNumber", "InvoiceT") + 1, 1) into the BeforeUpdate event.

  3. #3
    radian89 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Dec 2015
    Posts
    37
    Hi knarfreppep,

    thanks for the reply, but,

    Nope, it turns out not creating invoice number, and then, I couldn't fill in the subform, because the parent & child relation in the invoice number.

  4. #4
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Quote Originally Posted by radian89 View Post
    Hi knarfreppep,

    thanks for the reply, but,

    Nope, it turns out not creating invoice number, and then, I couldn't fill in the subform, because the parent & child relation in the invoice number.
    Nope ... I do it successfully with every data entry form I create, including those with subform(s).

  5. #5
    radian89 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Dec 2015
    Posts
    37
    Hi knarfreppep,

    Do you mind if you take a quick look on my database? the form is called "InvoiceF"

    thanks a lot for the help
    Attached Files Attached Files

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-06-2013, 03:06 PM
  2. Replies: 2
    Last Post: 12-20-2012, 03:06 PM
  3. Replies: 6
    Last Post: 09-02-2012, 04:30 PM
  4. Replies: 6
    Last Post: 08-22-2012, 03:24 AM
  5. delete record if 2 fields are blank
    By rlsublime in forum Access
    Replies: 1
    Last Post: 06-20-2012, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums