How can I "undo" an entry on a form/subform while still entering data?

M

mthornblad

Hi

I have a form/subform for entering invoice data. What can I do if I
realize that I have already entered the invoice ? Example: I enter
the main form data and enter 5 lines of detail on the subform and then
I realize that I have already entered this invoice before ? I would
love to have a button that I could click that "undoes" the entire
entry.

Is there a way to do this ?

Thanks in advance
Mark Thornblad
 
A

Allen Browne

When you enter the main form record, and move into the subform to enter the
line items, the header record saves into its table. Consequently you can't
just "undo" the record and whatever line items you have entered in the
subform.

Perhaps you could add a Delete button to the main form, and use cascading
deletes to delete the line items in the subform as well:

1. Open the Relationships window (Tools menu, or Database tab of the ribbon
in A2007). Create a relationship between tblInvoice.InvoiceID (the primary
key) and tblInvoiceDetail.InvoiceID (the foreigh key), and check the boxes
for:
[ ] Referential Integrity
[ ] Cascading Deletes

2. Open your main form in design view, and add a command button with these
properties:
Name cmdDelete
Caption Delete this invoice
On Click [Event procedure]

3. Click the Build button (...) beside the On Click property.
Access opens the code window.
Set up the code so it looks like this:

Private Sub cmdDelete_Click()
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
End Sub

Clicking the button will now delete the invoice, and the cascading delete
will delete any line items in that invoice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top