Deleting a record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to use a button on a form to delete a record. However, prior to the record being deleted I would like the record to be written to a deleted records table. I am going to use the following code to do this 'cause each record has about 100 fields
f_out.Addne
For i = 0 to f_in.Fields.Count -
f_out.Fields(i) = f_in.Fields(i
Nex
f_out.Updat
'delete record code her
'requery form code her
I am worried what will happen if the user cancels the delete action when the "confirm delete" message box appears. If this is the case then I don't want the record to be written to the deleted records table. Should I just move the f_out.update code to the end of the routine or is there a cleaner way of doing things
Thanks
 
One easier way: add a field to your table and use it as a boolean field to
show whether the record is "deleted" or "active". When the user "deletes" a
record, just set the value of this field to "deleted". If the user "cancels"
the deletion, set it to "active". This is most easily done with a boolean
field where True is active and False is deleted.

Then your form's recordsource query should filter on this field so that only
"active" records are shown.

This avoids the issue with which you're grappling.

--
Ken Snell
<MS ACCESS MVP>

Prokofiev said:
I want to use a button on a form to delete a record. However, prior to the
record being deleted I would like the record to be written to a deleted
records table. I am going to use the following code to do this 'cause each
record has about 100 fields:
f_out.Addnew
For i = 0 to f_in.Fields.Count -1
f_out.Fields(i) = f_in.Fields(i)
Next
f_out.Update
'delete record code here
'requery form code here
I am worried what will happen if the user cancels the delete action when
the "confirm delete" message box appears. If this is the case then I don't
want the record to be written to the deleted records table. Should I just
move the f_out.update code to the end of the routine or is there a cleaner
way of doing things.
 
Ken, I have done eactly what you said here. But I guess I
don't understand how to change to value of a field for the
selected record.

My form's underlying query has the field in it, but I
chose not to have a control forwhich the field is
represented.
 
You don't need a control .. just reference the field by its name:

Me.FieldName.Value = False

If you choose to use False as the value for a deleted record. Note that you
must include the field in the form's recordsource query.
 
Back
Top