[AccessD] Coding for backing up deletes

John W. Colby jwcolby at colbyconsulting.com
Wed Aug 4 10:10:38 CDT 2004


Paul,

The way I handle this is to have a control on the form which exposes (is
bound to) that field in the table, and is called the same thing on every
form.  In my case it is a Boolean value in the table, and thus a checkbox on
the form.  The checkboxes are always named chkActive and chkTrash on my
forms (in my code).  The code that intercepts the delete has access to the
form.  When the decision to actually perform the "delete" is made, MY code
simply clears the active and sets the trash by programmatically manipulating
those controls on the form.  

If you are using a "deleted" field and a text box called txtDeleted then the
code would look something like: 

me!txtDeleted = -1 '(which is the numeric value for True By The Way)
Me.dirty = false '(which saves that changed data)
Me.Requery	'To cause the form to no longer display the "deleted"
record.

The form's query has a where clause

Select MyData
>From MyTable
Where Deleted = False

Since you just set Deleted = true and requeried the form, the data
"disappears"

One important thing here though is to NOT try and just capture a delete
button click.  You should use the BeforeDelete event in the form.  In that
you ask the question "are you sure", then you cancel the delete (you don't
want a delete really happening) and you run the code that sets the Deleted
text box, saves the change and requeries the form.

The reason I caution against simply providing a delete button and trying to
capture that click is that a record can be deleted by selecting the record
and using the menu at the top (if the menu is exposed), selecting a record
and hitting the delete key, etc.  You want to capture ALL attempts to delete
the data through the form regardless of how they figure out to perform that
delete.  Capturing the BeforeDelete event and doing it there guarantees that
no deletes will be performed manually through that form.

John W. Colby
www.ColbyConsulting.com 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Paul Rodgers
Sent: Wednesday, August 04, 2004 10:24 AM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Coding for backing up deletes


I have a few minutes for this really interesting idea now. 

I have the field in the table, and the data type is Number.

1. I am not sure what is meant by "set the value for IsDeleted in that
record to -1" (By a bit  a coding?)

2. And - sorry - this escapes me too - "Then the form refreshes to NOT show
records where IsDeleted =-1" (Via a query?)

Be very pleased if you could let me know. Cheers paul 

-----Original Message-----
From: Darren DICK [mailto:d.dick at uws.edu.au]
Sent: Wednesday, August 04, 2004 1:43 AM

-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com






More information about the AccessD mailing list