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

M

mthornblad

Hi

I posted this question a couple of days ago and got 1 response but
couldn't read it. Hopefully someone will have and answer.

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.

How can this be accomplished ?

Thanks
Mark
 
A

Allen Browne

I posted this question a couple of days ago and got 1 response but
couldn't read it. Hopefully someone will have and answer.

Mark, here's the answer I posted to your question.
Hopefully it comes through as readable this time.

Previous reply:
==========
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.
 
M

mthornblad

I posted this question a couple of days ago and got 1 response but
couldn't read it. Hopefully someone will have and answer.

Mark, here's the answer I posted to your question.
Hopefully it comes through as readable this time.

Previous reply:
==========
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.

Allen

Thank you very much for your help. I did what you said and it worked
perfectly.
I hope everything is good "down under". You are a lifesaver !

Mark
 

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