delete subform record

C

Chris

My main form has subform [BCfrm]. The recorsource tables are related with
cascading deletes.

The user adds a record using DoCmd.GoToRecord , , acNewRec via a button and
then populates the main form, selects a service to promt the correct suborm
and populates it. Works fine. On the subform a control indicates the invoice
number that links it to the main form. I see it there...so doesn't that mean
the record is written in the related table?

I wish for the user to quit or abandon the entry via a Quit button. I can
only get the records (main and related) to delete when the user actually
enters data into the subform. They may wish to abandon before that.

So, the question is, how can I delete all related records, before an entry
(other than invoice number linked) into the subform? I have tried DoCmd Save
and several delete methods I've seen here. None work.

My code follows, with only one of several subforms indicated.

'allows each form to delete the record from its table.
Me.AllowDeletions = True
Me.BCfrm.Form.AllowDeletions = True
'turns off system messages
DoCmd.SetWarnings False
'deletes [tbl 2 Job] record and related tables' records
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
'turns system messages back on
DoCmd.SetWarnings True
Me.AllowDeletions = False
Me.BCfrm.Form.AllowDeletions = False

In hopes of guru help!

Thanks,
Chris
 
B

BruceM

Try pressing the Esc key twice. If that works, have you tried Me.Undo as a
command button click event?
 
C

Chris

Thank you Bruce! I got it working nicely now.

I stuck in me.undo and it left an empty record to view and it didn't remove
the related record. So, I used the following code and it tests fine removing
the main and subform record wherever the user quits. So, for anyone else in
need . . .

If Me.HasData1(InvNum) Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
Me.Undo
End If
Me.Requery 'puts back a valid record to view.
--
Thanks for your help,
Chris


BruceM said:
Try pressing the Esc key twice. If that works, have you tried Me.Undo as a
command button click event?

Chris said:
My main form has subform [BCfrm]. The recorsource tables are related with
cascading deletes.

The user adds a record using DoCmd.GoToRecord , , acNewRec via a button
and
then populates the main form, selects a service to promt the correct
suborm
and populates it. Works fine. On the subform a control indicates the
invoice
number that links it to the main form. I see it there...so doesn't that
mean
the record is written in the related table?

I wish for the user to quit or abandon the entry via a Quit button. I can
only get the records (main and related) to delete when the user actually
enters data into the subform. They may wish to abandon before that.

So, the question is, how can I delete all related records, before an entry
(other than invoice number linked) into the subform? I have tried DoCmd
Save
and several delete methods I've seen here. None work.

My code follows, with only one of several subforms indicated.

'allows each form to delete the record from its table.
Me.AllowDeletions = True
Me.BCfrm.Form.AllowDeletions = True
'turns off system messages
DoCmd.SetWarnings False
'deletes [tbl 2 Job] record and related tables' records
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
'turns system messages back on
DoCmd.SetWarnings True
Me.AllowDeletions = False
Me.BCfrm.Form.AllowDeletions = False

In hopes of guru help!

Thanks,
Chris
 

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

Similar Threads


Top