From: John on
Hi

On my Continuous Form sub form I have On Delete and After Del Confirm
events. They work fine when one record is deleted at a time but when user
selects and deletes multiple records the events do not work as required.
What is the correct method to handle deletion of multiple records?
Alternatively can I restrict users to only delete one record a time?

Thanks

Regards


From: Dirk Goldgar on
"John" <info(a)nospam.infovis.co.uk> wrote in message
news:OX$WjJyWKHA.2388(a)TK2MSFTNGP02.phx.gbl...
> Hi
>
> On my Continuous Form sub form I have On Delete and After Del Confirm
> events. They work fine when one record is deleted at a time but when user
> selects and deletes multiple records the events do not work as required.

What is "required"? The Delete event fires for every record deleted, while
the BeforeDelConfirm and AfterDelConfirm events fire only once.

> What is the correct method to handle deletion of multiple records?
> Alternatively can I restrict users to only delete one record a time?

I expect it would be possible via code to restrict deletion to only one
record at a time, but what the correct method would be to handle multiple
deletion has to depend on what it is you are trying to accomplish. What is
that?

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

From: John on
Hi Dirk

Many thanks. The code is as below;

Private Sub Form_Delete(Cancel As Integer)
GlbVar = Me.ID ' Picks the ID of the record before record is deleted
End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)
' Does processing using the record ID stored in GlbVar
End Sub

Thanks

Regards

"Dirk Goldgar" <dg(a)NOdataSPAMgnostics.com.invalid> wrote in message
news:eGubkQyWKHA.508(a)TK2MSFTNGP06.phx.gbl...
> "John" <info(a)nospam.infovis.co.uk> wrote in message
> news:OX$WjJyWKHA.2388(a)TK2MSFTNGP02.phx.gbl...
>> Hi
>>
>> On my Continuous Form sub form I have On Delete and After Del Confirm
>> events. They work fine when one record is deleted at a time but when user
>> selects and deletes multiple records the events do not work as required.
>
> What is "required"? The Delete event fires for every record deleted,
> while the BeforeDelConfirm and AfterDelConfirm events fire only once.
>
>> What is the correct method to handle deletion of multiple records?
>> Alternatively can I restrict users to only delete one record a time?
>
> I expect it would be possible via code to restrict deletion to only one
> record at a time, but what the correct method would be to handle multiple
> deletion has to depend on what it is you are trying to accomplish. What
> is that?
>
> --
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
>
> (please reply to the newsgroup)
>


From: Dirk Goldgar on
"John" <info(a)nospam.infovis.co.uk> wrote in message
news:OtFVyUyWKHA.4780(a)TK2MSFTNGP05.phx.gbl...
> Hi Dirk
>
> Many thanks. The code is as below;
>
> Private Sub Form_Delete(Cancel As Integer)
> GlbVar = Me.ID ' Picks the ID of the record before record is deleted
> End Sub
>
> Private Sub Form_AfterDelConfirm(Status As Integer)
> ' Does processing using the record ID stored in GlbVar
> End Sub


If you want to allow for multiple records to be deleted, you need to save
the IDs in something that can represent multiple items. That could be a
collection, or it could just be a string representing a comma-separated
list. You'd need to be sure to clear the collection/list in the
AfterDelConfirm event, so that it would be ready for the next delete action.

Here's a rough example (air code):

'------ start of example code ------
Private Sub Form_Delete(Cancel As Integer)

GlbVar = GlbVar & "," & Me.ID ' Add ID of record to list

End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)

Dim astrDeleted() As String
Dim strID As String
Dim I As Long

If Len(GlbVar) > 0 Then

' Process the deleted ID(s).

astrDeleted = Split(Mid$(GlbVar, 2), ",")

For I = LBound(astrDeleted) to UBound(astrDeleted)

strID = astrDeleted(I)

' Do something with the ID stored in strID ...

Next I

End If

End Sub
'------ End of example code ------

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)