Thank you for the response Allen. I actually saw this on a previous
thread
and I plan on using it for the unsaved record.
This is a saved record that I am attempting to delete and I am using
something very similar to the second part of your argument. It does
erase
it, but it doesn't remove it from the table. I'm using 2000 and I have
some
controls on the form that are locked. Do you think this has anything to
do
with it?
--
http://njgin.aclink.org
:
No, you do not need to execute a SQL statement if you are deleting a
record
from a bound form.
The record cannot be "deleted" if it is a new one (unsaved new record).
If
it is dirty at all, Access has to undo or save it. Saving (the default)
makes no sense, particularly as it might save, so try somthing like
this:
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
MaterialSum
DoCmd.Close acForm, Me.Name
End If
That should generate the built-in delete confirmation message. You can
have
your custom one as well if you wish.
If you still believe the record is not being deleted, add this line
just
before the RunCommand:
Debug.Print Me.[ID]
substituting your primary key field name for ID. You should then see
the
primary key value of the record that was deleted in the Immediate
Window
(Ctrl+G) after this runs. You can then investigate whether the
remaining
blank record is the same one, or is being caused by some other means
(e.g.
faulty code in the Current event of the Form.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Well, its an Event Procedure from a command button that runs this
code.
Do I
then need to run an SQL statement to remove the record from the
table?
--
http://njgin.aclink.org
:
You need run a SQL like this:
DELETE [table.*]
FROM table
WHERE criteria
maybe this help you
--
Lorenzo DÃaz
Cad Technician
:
I've got a command button that uses the following to delete a
record:
Response = MsgBox("Delete The Current Material?", vbYesNo)
If Response = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
MaterialSum
DoCmd.RunCommand acCmdCloseWindow
ElseIf Response = vbNo Then
Exit Sub
End If
Where MaterialSum is a module that totals the price to the main
form
using
Dsum. It works, sort of... The record is zero'd out so that all
the
fields
are empty but it is not deleted from the table. Is this because I
have
controls that are locked? Or rather, are there any suggestions as
to
why
this might be happening?