Re: delete record in a main form and any link records in the subform



"hngo" <hngo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1EE43FFC-C635-4016-8992-5BCDF21A98A4@xxxxxxxxxxxxx
> my problems is that if the subform dont have any record the system
> return with a MICROSOFT OFFICE ACCESS MESSAGE - "NO CURRENT REORD"
>
> CLICK "OK"
>
> however the system does not delete the record in the mainform. Can
> anyone help?
>
> My coding is as follows:
> Private Sub Delete_equipment_Click()
> On Error GoTo Err_Delete_equipment_Click
> Dim Msg, Style, Title, Help, Ctxt, Response, MyString
> Msg = "you are about to IRREVERSIBLY DELETE *ALL*INFORMATION
> CONCERNING THIS MAIN EQUIPMENT FROM THE DATABASE!?" ' Define
> message. Style = vbOKCancel + vbCritical + vbDefaultButton2 '
> Define buttons. Title = "ARE YOU 100% SURE!!!?" ' Define title.
> Response = MsgBox(Msg, Style, Title)
> If Response = vbOK Then ' User chose Ok.
> Me.AllowDeletions = True
> Me.FORM_conveyor_data.Form.Recordset.Delete
> 'Me.Form_Brake.Form.Recordset.Delete
> 'Me.Form_Backstop.Form.Recordset.Delete
> 'Me.Form_Coupling.Form.Recordset.Delete
> 'Me.Form_CV_GearBox.Form.Recordset.Delete
> 'Me.FORM_CV_pulley.Form.Recordset.Delete
> 'Me.Form_motor_equipment.Form.Recordset.Delete
> 'Me.Form_Instrumentation.Form.Recordset.Delete
> Me.[sub equipment details].Form.Recordset.Delete
> DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
> DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
> End If
> Exit_Delete_equipment_Click:
> Exit Sub
>
> Err_Delete_equipment_Click:
> MsgBox Err.DESCRIPTION
> Resume Exit_Delete_equipment_Click
>
> End Sub
>
>
> Many thanks in advance

The simplest, no-code way to support this process is to set "Cascade
Deletes" on the relationship between the main form's table and the
subform's table. If you do that, you don't have to do anything special
to delete the subform's records.

If for some reason you don't want to use Cascade Deletes, then you could
just run a delete query to delete all related records, then requery the
subform. For example:

CurrentDb.Execute _
"DELETE * FROM Conveyer_Data " & _
"WHERE EquipmentID = " & Me!EquipmentID,
dbFailOnError

Me!FORM_conveyor_data.Requery

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.


Loading