Delete events on a Continuous Form sub form

  • Thread starter Thread starter John
  • Start date Start date
J

John

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
 
John said:
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?
 
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
 
John said:
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 ------
 
Back
Top