Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Record using VBA

Status
Not open for further replies.

illini

Technical User
Aug 2, 2002
89
FR
Currently, I'm using DoCmds to open a query, select a record, and delete it. Here's the way it looks.

DoCmd.OpenQuery "Qry_Rec", acViewNormal, acEdit
DoCmd.GoToRecord acDataQuery, "Qry_Rec", acFirst
DoCmd.RunMacro "Macro1" 'RunCommand / DeleteRecord
DoCmd.Close acQuery, "Qry_Rec", acSaveNo

When I run this, the user actually sees the query open, the record deleted, and the query closed.

Is there any better way, using vba, to delete a specific record?

-illini
 
Dim strSQL As String

strSQL = "Delete tlbName.* From tblName Where criteria"
DoCmd.RunSQL strSQL

If you look at the SQL in the SQL View of your delete query you will see the exact SQL you need to do what you are asking. Just hook it into the DoCmd.RunSQL statement as above.

Good Luck!

PS. Make sure you back up your table first in case it does not work as planned the first time (Rarely happens of course).
 
Thankyou very much. That works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top