How to Delete the Current Record via VB in a Form

  • Thread starter Thread starter HumanJHawkins
  • Start date Start date
H

HumanJHawkins

Hi all,

I have tried several other things that were not directly an answer to
this from other posts, but have not had success. I have code that finds
the record I want to delete, but I can't figure out the delete part:

Me.AllowDeletions = True
Me.iTheKeyField.SetFocus
DoCmd.FindRecord Me.SearchForDeletion

' Make sure FindRecord didn't fail and leave us on a different
record
If (Me.iTheKeyField = Me.SearchForDeletion) Then

' Delete the current record!!!

Me.Requery
End If

Me.AllowDeletions = False

In case it matters, this is an .adp connected to a SQL data source.

Thanks in advance for any help!
 
Human,

DoCmd.RunCommand acCmdDeleteRecord

I assume that works in an ADP (I've never tried).
You will probably want to wrap the above line in
DoCmd.SetWarnings False/True

I doubt that the Me.Requery will be necessary
 
I am guessing this is going to work... I found that it wasn't working
because the "FindRecord" command appears to just set the focus to the
found record, but not update the "CurrentRecord"

So my safety-valve that prevents deletion if the current record is not
correct was preventing it from deleting.

Thanks for the help.
 
Back
Top