How to Delete the Current Record via VB in a Form

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!
 
S

Steve Schapel

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
 
H

HumanJHawkins

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.
 

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

Top