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.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"scratchtrax" <(E-Mail Removed)> wrote in message
news:A1EE1B69-CCC8-41E5-BED5-(E-Mail Removed)...
> 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
>
>
> "ldiaz" wrote:
>
>> You need run a SQL like this:
>>
>> DELETE [table.*]
>> FROM table
>> WHERE criteria
>>
>> maybe this help you
>>
>>
>> --
>> Lorenzo Díaz
>> Cad Technician
>>
>>
>> "scratchtrax" wrote:
>>
>> > 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?
>> > --
>> > http://njgin.aclink.org