dt21823
07-23-2004, 06:55 AM
I have a db setup to track customers and invoices. Design is as follows.
customers tbl:
customerID-PriKey (autonumber)
name
address
phone
invoices tbl:
invoiceID-PriKey (autonumber)
customerID
subtotal
tax
total
invoiceitems tbl:
ID-PriKey (autonumber)
invoiceID
item
price
quantity
total
One-to-many relationships are setup between customers and invoices based on customerID and between invoices and invoiceitems based on invoiceID. I have a single form for customers with nested subforms for invoices and invoiceitems. My goal is to have a single form to browse and add customers and browse and add invoices.
The challenge I am running into is that a new records has to be created in the invoices table before items can be entered for a new invoice. This is a challenge because all of the fields in the invoices table are either autonumbered (invoiceID), based on a foreign key (customerID) or calculated (subtotal, tax, total). So it doesn't make sense to require the user to enter data that creates a new record in the invoices table before they start entering invoice items.
My solution so far has been to use the On Enter event of the invoices subform to set the customerID field to that of the current customer and save the record before the user can enter invoice items. That works except if the user is browsing invoice records and browses to a new record, it bypasses the On Enter event and the user gets an error trying to enter invoice items. I've tried adding VBA code to set the focus on a control on the main form and to enable/disable the subforms, but that has just caused other issues. Another challenge is that invoice records can get created without associated invoice items ever being entered.
How can I improve my table and form design given my goal of managing customers and invoices on one form? Is there a way to ensure an invoice record gets created before items are entered for a new invoice? What can I do to prevent or cleanup invoice records that get created with no associated invoice items?
Thanks in advance for your help and sorry this is kinda long winded.
customers tbl:
customerID-PriKey (autonumber)
name
address
phone
invoices tbl:
invoiceID-PriKey (autonumber)
customerID
subtotal
tax
total
invoiceitems tbl:
ID-PriKey (autonumber)
invoiceID
item
price
quantity
total
One-to-many relationships are setup between customers and invoices based on customerID and between invoices and invoiceitems based on invoiceID. I have a single form for customers with nested subforms for invoices and invoiceitems. My goal is to have a single form to browse and add customers and browse and add invoices.
The challenge I am running into is that a new records has to be created in the invoices table before items can be entered for a new invoice. This is a challenge because all of the fields in the invoices table are either autonumbered (invoiceID), based on a foreign key (customerID) or calculated (subtotal, tax, total). So it doesn't make sense to require the user to enter data that creates a new record in the invoices table before they start entering invoice items.
My solution so far has been to use the On Enter event of the invoices subform to set the customerID field to that of the current customer and save the record before the user can enter invoice items. That works except if the user is browsing invoice records and browses to a new record, it bypasses the On Enter event and the user gets an error trying to enter invoice items. I've tried adding VBA code to set the focus on a control on the main form and to enable/disable the subforms, but that has just caused other issues. Another challenge is that invoice records can get created without associated invoice items ever being entered.
How can I improve my table and form design given my goal of managing customers and invoices on one form? Is there a way to ensure an invoice record gets created before items are entered for a new invoice? What can I do to prevent or cleanup invoice records that get created with no associated invoice items?
Thanks in advance for your help and sorry this is kinda long winded.