Form_BeforeDelConfirm Question

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

Guest

When the user tries to delete a record, I would like to check the value of
one of the fields in the record to determine if the deletion is allowed.

For example: say the form's underlying data is different types of expenses.
I don't want the user to be able to delete expenses named "Administration".

So I put the following code into the Form_BeforeDelConfirm event:

If me.txtExpense = "Administration" then
msgbox "You cannot delete the admin fee"
cancel = true
endif

when I track the value of me.txtExpense in this event procedure, the value
is null.

Any ideas on how I can check the value of a field in a record that is about
to be deleted?

Thanks,
Rob
 
Rob LMS said:
When the user tries to delete a record, I would like to check the
value of one of the fields in the record to determine if the deletion
is allowed.

For example: say the form's underlying data is different types of
expenses. I don't want the user to be able to delete expenses named
"Administration".

So I put the following code into the Form_BeforeDelConfirm event:

If me.txtExpense = "Administration" then
msgbox "You cannot delete the admin fee"
cancel = true
endif

when I track the value of me.txtExpense in this event procedure, the
value is null.

Any ideas on how I can check the value of a field in a record that is
about to be deleted?

In the BeforeDelConfirm event, the record has already been deleted, but
it was done within a transaction so that the record can be restored if
the user requests it. Use the form's Delete event instead. When that
event fires, the record hasn't yet been deleted, so you can still check
the values of its fields.
 
Thanks Dirk. Worked like a charm.

Dirk Goldgar said:
In the BeforeDelConfirm event, the record has already been deleted, but
it was done within a transaction so that the record can be restored if
the user requests it. Use the form's Delete event instead. When that
event fires, the record hasn't yet been deleted, so you can still check
the values of its fields.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top