Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eliminating New Record After Delete

Status
Not open for further replies.

Genimuse

Programmer
May 15, 2003
1,797
US
With a fairly simple form that's connected to a recordset I added a Delete This Record button using the wizard. I tacked on a bit of additional code to delete some foreign data at the same time.

This does indeed work: it deletes the current record and runs the extra code. However, it also automatically creates a new, blank record and, appropriately (but not what I want) runs the form's OnCurrent code.

I can't figure out what to do to stop it from generating the new record after delete. I've set the Cycle to Current Record, thinking that might be related, but no. I've created a flag that prevents any code from running in the OnCurrent (besides checking for the flag) if a delete was just completed, but no.

It seems likely that this is a very simple thing to fix, but I've thwacked my head on it for a number of hours and figured I'd best turn to folks whose brains aren't mush. Any thoughts?
 
What about setting the AllowAdditions property of the Form to False ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Good idea. Unfortunately that breaks my
Code:
DoCmd.GoToRecord , , acNewRec
later. Is there another way to add a new record and then go to it that will slip by the AllowAdditions being set to false?

Thanks much for your response, btw. I really appreciate any suggestions.
 
Sorry, to clarify, I know how to insert a new record via SQL, but not how to jump to that new record.
 
There isn't a new record created until you add some data to a field in the recordset. If you just move off the 'new' record (for example Me.Recordset.MoveFirst) I believe you won't have any issues.
 
I tried to just programmatically jump to the previous record at that point, but the new fake stuck around.

In the end I had the code:

1. Store the ID of the current record.

2. Jump to the first record (will only not work if the user is trying to delete the first record, but I know in this particular case that it won't happen).

3. Delete the record with the stored ID

4. Requery (or #5 will fail)

5. Jump to the last record.

It feels very clumsy and wouldn't work in all kinds of situations. Fortunately it will work here. Wish I had a better understanding of the event model so I could figure out what was happening that made it save that new false record.
 
Genimuse,
I just created a simple form and tried to duplicate your issue. My button deleted the record and didn't trigger the OnCurrent event. Can you post the code you added to the wizard generated Delete code? You must do something to make the form move to a new record.
 
I know that the situation is unusual as I've put delete buttons like that on forms many times. I'm certain that it relates to some calculations I'm doing OnCurrent, at least one of which is probably setting a form field value (one sets the date based on the previous calendar click, for example) and the record is therefore saving itself. Unfortunately I've given this way too much time and have spent a number of unpaid hours tracking it down. At this point, with a successful workaround in place, I'm just going to have to let it lie. One of those things I hate to do as a programmer but sometimes have to do as a bookkeeper.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top