? post deleted

  • Thread starter Thread starter alvin Kuiper
  • Start date Start date
A

alvin Kuiper

Hi
I just making a Log table , and i need to see a product number there has
been deleted, when i try get the produkt nr it is allways the next number i
can see, because Access go to the next record, but isn't a wat to cash the
number the user has deleted ?

Ak
 
alvin Kuiper said:
Hi
I just making a Log table , and i need to see a product number there has
been deleted, when i try get the produkt nr it is allways the next number
i
can see, because Access go to the next record, but isn't a wat to cash the
number the user has deleted ?


I'm not at all sure I understand what you are asking. I *think* maybe you
are trying to use a form's AfterDelConfirm event to record the product
number (a field value) of the record that was deleted. The problem there is
that, in both the BeforeDelConfrm and AfterDelConfirm events, the record has
already been deleted and removed from the form, so getting Me.ProductNumber
gives you the number of a different record from the one that has been
deleted. Is that the issue you're trying to solve?

If so, there are really two things you have to consider. First, there could
be more than one record deleted in a single operation. Second, you have to
capture the information about the deleted records in the form's Delete
event, because that fires for each deleted record. But you won't know
whether those records actually *stayed* deleted until the AfterDelConfirm
event.

One way to handle this is to use a module-level collection to save the
product number of each deleted record, then get the information from that
collection in the AfterDelConfirm event. Here's some example code:

'----- start of example code for form's module -----
Option Compare Database
Option Explicit

Dim mcolDeleted As New Collection

Private Sub Form_AfterDelConfirm(Status As Integer)

Dim strDeletedItems As String
Dim I As Long

With mcolDeleted
For I = 1 To .Count
strDeletedItems = strDeletedItems & ", " & .Item(I)
Next I
End With

If Status = acDeleteOK Then
' This is where you would do your logging.
MsgBox "Deleted these products: " & Mid(strDeletedItems, 3)
End If

' Empty the collection for next delete operation.
While mcolDeleted.Count > 0
mcolDeleted.Remove 1
Wend

End Sub

Private Sub Form_Delete(Cancel As Integer)

mcolDeleted.Add Me.ProductNumber.Value

End Sub
'----- end of example code for form's module -----
 
What I do is never actually delete a record. I have a column in the table
called "Deleted" as a Yes/No field type. I default it to 0 (zero) on record
adds. When I want to "delete" a record, I set it to "Yes". My bound forms are
set-up to ignore records with Deleted = Yes. So are my reports.

Works like a charm, and I can get to ANY "deleted" record whenever I might
need to.
 
Back
Top