Custom Record Deletion Sequence (1 Viewer)

shadow9449

Registered User.
Local time
Yesterday, 20:50
Joined
Mar 5, 2004
Messages
1,037
I want to create a custom sequence when deleting a record but I'm having a problem.

What I want to do is prompt the user for the reason he/she is deleting the record and then archive this so it can be viewed in a log at a later time. This extra step is not as easy as I thought it would be.

What I did was put some coding into the On Delete event of the form. The code opens a form with a text box. The user can enter the reason for the delete in the text box and click OK or click cancel to abort the deletion.

My problem here is opening another form from the On Delete event. As soon as the form is open, the code just passes to the next step of the sequence and deletes the record.

There are 2 approaches that I've thought of but I'm not happy with either.

Approach 1:
In the On Delete event, set Cancel to True. That way the deletion is not handled by the delete sequence but rather by the new form that opens. The problem is that deleting a record from another form is not that simple. What I've tried is to execute a SQL statement that grabs the ID of the record from the open form and delete it. The problem is that although the record is deleted, all the fields on the form say #Deleted in them which is not that pretty. (Maybe there's some other way to do the deletion without this problem that I'm not aware of...?)

Approach 2:
Use an Inputbox. Unlike a custom form, the Inputbox delays execution of the code so the code can determine from the results (i.e. should it cancel the delete if the user clicked Cancel). The problem with Inputboxes is that they are not very flexible in the layout, they look pretty "packaged" (i.e. they look to me like the programmer didn't bother creating a means to enter a value). There's no way to place the buttons where you want or have it do better validation (e.g. I want the FORM to check that there's at least a few words describing why the user is deleting the invoice rather than have the form with the record get the input message passed back and then give an error and then pop open the Inputbox again)

I think that especially when you're creating an application with anything financial, you'll want to log a deleted invoice including the date, amount, possibly the client's name, invoice number, reason for deletion and the login name of the person doing the deletion. All of these are easy to record other than the reason.

Help would be much appreciated.

SHADOW
 
Last edited:

RuralGuy

AWF VIP
Local time
Yesterday, 18:50
Joined
Jul 2, 2005
Messages
13,826
Try opening the other form with the Dialog argument which will stop the code execution in the first form.
 

shadow9449

Registered User.
Local time
Yesterday, 20:50
Joined
Mar 5, 2004
Messages
1,037
Try opening the other form with the Dialog argument which will stop the code execution in the first form.

That worked perfectly. I've been using Access for 13 years now (since Access 2.0) and I've never known about the Dialog argument!

Thank you very much! :)

SHADOW
 

RuralGuy

AWF VIP
Local time
Yesterday, 18:50
Joined
Jul 2, 2005
Messages
13,826
Glad I could help. There is always something new to learn somewhere. ;)
 

shadow9449

Registered User.
Local time
Yesterday, 20:50
Joined
Mar 5, 2004
Messages
1,037
Glad I could help. There is always something new to learn somewhere. ;)

You're right. It's also possible that someone else will see this thread and use the idea of logging deletions.

A few weeks ago, all the staff of the office of one of my clients went on vacation except for one person. When they came back, she strangely didn't have any cash for the manager to take to the bank. The manager called me up and asked me how to tell if invoices are gone and found that 5 invoices had been deleted. In my application, there is an MRU list of the 25 most recently accessed client files. She called up a few and told them that she was doing a survey to determine the quality of client care and wanted to know when they last made a purchase. Sure enough, 5 people had been in and made purchases that were strangely not in the program.

Since that point, I feel that I want to allow invoices to be deleted (at least by a user with Administrative privileges) but keeping a log of when, who and why (and how much) is being deleted can be a great idea for the scenario in the previous paragraph or for accounting/auditing purposes and so on.

SHADOW
 

RuralGuy

AWF VIP
Local time
Yesterday, 18:50
Joined
Jul 2, 2005
Messages
13,826
All too true. Audit trails definately have a place in many current applications.
 

Users who are viewing this thread

Top Bottom