Deleting data on mainform/subform set up.

kamulegs

Registered User.
Local time
Today, 22:40
Joined
Aug 23, 2010
Messages
12
Greetings all

I have main form/subform set up and i wanted to include a delete button on the main form( the undo created with wizard button doesnt work ) .

I have tried the code below but it takes like 2 minutes to execute. Deleting just a few records(like 4).
tblBooking is main table and tblBookingDetails is the child table. BookingID is PK for main and FK in child.

Here is the code i tried
Code:
Private Sub cmdDelete_Click()
Dim strSql2 As String
Dim strSql3 As String
On Error GoTo ErrorMine
strSql3 = "DELETE *  From " & _
 "tblBookingDetails Where BookingID = " & Me!BookingID

strSql2 = "DELETE *  From " & _
 "tblBookings Where BookingID = " & Me!BookingID
  DoCmd.RunSQL strSql3
 
 DoCmd.RunSQL strSql2
cmd_Exit:
Exit Sub
ErrorMine:
MsgBox "Error" & Err.Description
Resume cmd_Exit
End Sub
I am looking for guidance on a faster way of doing it.

Thanks

Ronald.
 
What do you want to delete 1 record and its related records or entire tables?

Wont this delete the main record and its related records... Put command button on the main form with code:

Code:
Private Sub deletebutton_Click()
On Error GoTo Err_deletebutton_Click
 
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
Exit_deletebutton_Click:
    Exit Sub
Err_deletebutton_Click:
    MsgBox Err.Description
    Resume Exit_deletebutton_Click
 
End Sub
 
What do you want to delete 1 record and its related records or entire tables?

Wont this delete the main record and its related records... Put command button on the main form with code:

Code:
Private Sub deletebutton_Click()
On Error GoTo Err_deletebutton_Click
 
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
Exit_deletebutton_Click:
    Exit Sub
Err_deletebutton_Click:
    MsgBox Err.Description
    Resume Exit_deletebutton_Click
 
End Sub

Thanks so much

it has worked after i implemented cascade delete.
But i believe it is ok because if a booking is deleted, all the related information should be deleted
 
Yes thats right. As long as your relationships are correct deleting a booking will also remove all that particular bookings data such as booking details.
 

Users who are viewing this thread

Back
Top Bottom