Prevent saving record if no details in subform

sv89

Registered User.
Local time
Today, 00:09
Joined
Nov 3, 2010
Messages
40
Hi,

I have a bound form Invoice and a bound subform InvoiceDetails joined by InvoiceID. How do I prevent saving a record in tblInvoice if the InvoiceDetails section is empty?
 
What is the relationships between two tables, (Invoice and InvoiceDetails) ??
 
You should prevent the user from going to a new record in the first place.

Perform a DCount() on InvoiceDetails and if it's zero set the Allow Additions property to False, Else set it to True.
 
I have the code below for sbfrmInvoiceDetails but it doesn't seem to work:

Private Sub Form_AfterUpdate()

If Me.totUnits = 0 Then
Forms!frmInvoices.AllowAdditions = False
Else
Forms!frmInvoices.AllowAdditions = True
End If

End Sub

totUnits is a calculated field on sbfrmInvoiceDetails. totUnits = Count([OrderLineNum])
 
personally, i think it goes back a stage - what is driving your invoice? - what causes an invoice to need to be prepared?

much of this depends on your process - after all, you may have instant cash sales, but you may also have account invoices, which you prepare at a given point in time

the best way may be to use a temporary sales table to hold the items that will be on the invoice - then raise the invoice when the order is complete.
 
My frmInvoices can be compared to the Orders form in the Nwind example. You select a Product from a combo box in the Orders subform to add it to the Order. The Nwind example lets you save the record in Orders and move on to the next one even if there aren't any products selected in the Orders subform. I want to prevent saving the record in Orders if there are no details in the Orders subform.

I hope I'm clear enough.
 
I have the code below for sbfrmInvoiceDetails but it doesn't seem to work:
Put the code in the Current Event of the main form and in the After Update event of the subform:
Code:
Current event of main form:
    If IsError(Me.totUnits) Then
        Me.AllowAdditions = False
    Else
        Me.AllowAdditions = (Nz(Me.[COLOR=red]NameOfSubformControl[/COLOR].Form.totUnits, 0) <> 0)
    End If
 
After Update event of subform:
Me.Parent.AllowAdditions = (Nz(Me.totUnits, 0) <> 0)
Obviously take into consideration what gemma-the-husky mentioned.
 

Users who are viewing this thread

Back
Top Bottom