Button to delete a record

Quasius

Registered User.
Local time
Today, 16:14
Joined
Jul 30, 2002
Messages
13
Is it possible to make a button in a form to delete an entire record? It would actually have delete rows from several tables, since each record is across multiple tables. Also if it could have a confirmation box such as "Are you sure you want to delete the entire record?" that would be great. Thanks.
 
You must have a unique field in each table linked all the tables together. If they are One-To-Many links, you have to delete the Many side table first, then delete the One side table.

Private Sub Command0_Click()
Dim dbs As Database
If MsgBox("Wanna delete '" & Me.ID & "'?", vbYesNo, "Sure?") = vbOK Then
dbs.Execute "Delete * From Your1stManySiteTableNameHere Where ID=" Me.ID
dbs.Execute "Delete * From Your1stManySiteTableNameHere Where ID=" Me.ID
.
.
.
dbs.Execute "Delete * From YourNManySiteTableNameHere Where ID=" Me.ID
dbs.Execute "Delete * From YourOneSiteTableNameHere Where ID=" Me.ID
Else
Exit Sub
End If
End Sub

I assume the unique field is ID with Number format.

Sure, BACK UP your tables b4 doing this.

If you want to do sthg like this in the future, make sure you select Cascade Delete Related Fields when you set up the Rels. of the tables.
 

Users who are viewing this thread

Back
Top Bottom