Access 2010 Delete a record
Posted on 2012-09-05
I am trying to use vba code (behind a button) to delete a passenger record shown in a form. However, there is a subform in the main form that contains "bookings" associated with this passenger and i do not wish the delete command to run if there are any bookings associated. I have tried the below code and it seems to partly work, however, it will not allow me to delete a record even if it has no booking.
If IsNull(mfrmPassenger_ID) Then ' checks to see whether form has a record at all
If MsgBox("Are you sure you wish to Delete this Passenger? You will not be able to view this record afterwards!", vbYesNo) = vbYes Then
If Not IsNull([NewBooking_Datasheet].Form![ViewBooking]) Then ' control in subform
MsgBox "Cannot Delete"
'Cancel = True
DoCmd.GoToRecord , , acNewRec
Any ideas would be welcome?