RunCommand acCmdDeleteRecord deletes record, but blank new record inserted immediately afterwards

I have a problem where I have a parent form (fEditAgreement) and a continuous subform (tTerm_subform) that displays related records.  Each instance of the term subform contains an Edit button.  When that Edit button is clicked, a new form (fEditTerm) is opened that is filtered to that term.  This works fine.  However, I also have a delete button on fEditTerm.  I currently have the onClick event set to the function below:

Private Sub cmdDeleteTerm_Click()
    'Delete item
    RunCommand acCmdDeleteRecord
               
    'Close form
    DoCmd.Close acForm, "fEditTerm"
   
    'Refresh subform
    Form_fEditAgreement.tTerm_subform.Requery
End Sub

What ends up happening is that the current record in fEditTerm is deleted, but a blank new record is immediately inserted at the same time.  How do I keep that blank record from being inserted?

Thanks,

-Tim
emilysamAsked:
Who is Participating?
 
harfangCommented:
Considering the code:

    'Delete item
    RunCommand acCmdDeleteRecord
                                       <----- what happens here?                
    'Close form
    DoCmd.Close acForm, "fEditTerm"

After the record is deleted, the form displays a new record. The event Form_Current is triggered, even for the Me.NewRecord.
Do you have something happening in the Form_Current Event? For example setting of some default values?

Another idea is to add:

    Me.AllowAdditions = False

Just before the Delete command. This way, the new blank record is never created. And thus cannot be saved.

Yet another idea:

Put "Stop" just before the delete command. Then execute line by line. You should see Form_Current if that event has a handler.

Good Hunting!
0
 
Data-ManCOOCommented:
Can the users add new records in the subform?  If you don't want them to do this change the Allow Additions property of the suform to no.

What happens if you perform the requery before you close the fEditTerm form?

Normally when a requery occurs the focus is on the first record.

Mike
0
 
emilysamAuthor Commented:
The fEditTerm subform is doing dual-duty as an add and an Edit form.

Putting in the line Me.AllowAdditions = False before the delete works fine.  However, I now get a confirmation prompt that I wasn't getting before "Are you sure you want to delete this record?".  How do I turn that off?

0
 
emilysamAuthor Commented:
Figured it out.  Had to use:

    DoCmd.SetWarnings False

and

    DoCmd.SetWarnings True

Before and after the delete statement.

Thanks.  Since you both got the answer right, I'm splitting the points
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.