Event after delete

Kenln

Registered User.
Local time
Today, 01:28
Joined
Oct 11, 2006
Messages
551
I am having trouble locating an Event that triggers when you delete the last record in a table.

Here is the problem:
I have a Form with two subForms (sfrm_Main and sfrm_Sum). When I change data or add a record on sfrm_Main I want (and it works) sfrm_Sum to update (requery).

I place the following code in
Form_AfterUpdate()
Form_AfterInsert()

Code:
Me.Parent!sfrm_Sum_.Requery
Yeah!!!

But when I delete a record, nothing...
and I do not see a 'Form_OnDelete()???
and 'Form_Delete(Cancel As Integer)' doesn't seem to be called.

Does anyone know what Event triggers after a record is deleted???

Thank you,
 
P.S.
I tried 'Form_AfterDelConfirm(Status As Integer)' also
But it doesn't work either.
 
i assume your form or subform is set to not allow addiitons, perhaps the dataset is non updateable, but probably not that, as you are deleting records with the form

in such cases, however, if you have an empty dataset, you get a curious behaviour where nothing happens

you dont see any controls on the form, and no events happen - theres no current record

its not an error- its just access behaviour, but it does produce some strange side effects

is that whats happened?
 
sfrm_Main is set to allow additions and workds fine. sfrm_Sum is from a sum query and does not allow edits or additions. If I go directly to the table for sfrm_Main and delete all records, when I open the form (which includes sfrm_Main and sfrm_Sum) I can add, delete or edit, data to sfrm_Main. When I add or edit data on a given records, when I leave (exit) that specific record the sfrm_Sum updates. However sfrm_Sum does not update when I delete a record in sfrm_Main.
 
you probably havent got any refereential integrity set, if you can delete a main record, while linked records remain - you will end up weith floating records ...

i;m not sure, but if you delete a record, your main form will goto a different record, so possibly you need the current event to requery the subform, if its not happening automatically
 
Did you copy this:
Me.Parent!sfrm_Sum_.Requery
or type it in here?

If you copied and pasted, I'm surprised you didn't get an error as it would with the underscore and then period:

Also, it Should be:
Me.Parent!sfrm_Sum.Form.Requery

But, make sure that sfrm_Sum is actually the name of the container control on the main form as it might be different from the subform and remember you must use the CONTAINER name when referencing it.
 
Yep, the dot was my bad typing on the post and does not actually exist in the code. Even if I add 'form' as in
Me.Parent!sfrm_Sum.Form.Requery
It still does not work since I cannot find an event that is triggered. I am going to use a workaround.

I set Allow Deletions to no on the sub form. This will prevent user from clicking a record and pressing delete. Then I will add a delete record button that deletes the record on the sub form.

I haven't deleted a record on a subform from a Main form so if I get stuck I'll be back. Otherwise this is a workable solution though not as direct as I started.
 
To add to CyberLinx's answer

There is no separate event that triggers after a recordset delete. The OnCurrent event triggers after ANYTHING that navigates or modifies the underlying recordset, including a simple MOVENEXT or MOVEPREV action.

Deleting a record isn't a form event. It is a recordset event, and there are no events associated with recordsets per se. The only way to know it was a delete in the context of the form is to set a form-global flag in a "BeforeDelete" event and on the next "OnCurrent" event, see if the flag is set.

If you have the ability to sometimes cancel a delete, then either cancel the delete OR set the flag, not both.
 
i assume your form or subform is set to not allow addiitons, perhaps the dataset is non updateable, but probably not that, as you are deleting records with the form

in such cases, however, if you have an empty dataset, you get a curious behaviour where nothing happens

you dont see any controls on the form, and no events happen - theres no current record

its not an error- its just access behaviour, but it does produce some strange side effects

is that whats happened?
Thats just what has happen to me.. :(
I guess i have alot more to learn about access.
 
i assume your form or subform is set to not allow addiitons, perhaps the dataset is non updateable, but probably not that, as you are deleting records with the form

in such cases, however, if you have an empty dataset, you get a curious behaviour where nothing happens

you dont see any controls on the form, and no events happen - theres no current record

its not an error- its just access behaviour, but it does produce some strange side effects

is that whats happened?
Hi gemma,

I have exactly the behaviour you describe - an empty form (no controls) after deleting a record.

Do you know how to prevent this.

I have a form with a subform (customers (parent) and delivering addresses (subform)) and I delete a customer by clicking a command button which ist just running one command:

docmd.runcommand accmddeleterecord

Can you help. Please advice.

Best regards. Mary
 
I use something like this

Code:
If Me.RecordsetClone.RecordCount = 0 Then
     Do something like close the form, open a message box, both, etc...
End If
 
Hi Kenin,

Thanks for your prompt answer.

I thought of that as well, but know I found a smarter solution.

I had a filter set to the form so that it only showed one record at a time. I did that because I wanted the user to prevent record scrolling by mouse scrolling (what is the english word for that uups) and it had no records because of that.

Now I delete the filter after the delete event and than set it again to an existing record.
 

Users who are viewing this thread

Back
Top Bottom