0
votes

I have forms as below.

Parent Form : CustomerForm Child Form : OrderForm - in DataSheet view

Each customer can have more orders.

if i select a order and click 'Delete' button, it has to delete. I am not able to get current record and its fields.

No = Me.Form.CurrentRecord

Someone pls help.

Thanks.

1
What do you mean by "I an not able to get current record". In DataSheet view you can simply select the entire row and press delete on your keyboard. If not, you might have disabled this in the properties. I also do not understand what the code is supposed to be for. What is No? Give some more information, else you can't be helped - Roland
'No' is simply a variable to store the currentRecord. Ya. I tried deleting in the way u told. My requirement is to explicity have a 'Delete' button and click event for it to delete the current record. So I thought in order to delete the current record, I need to find some index of it. Can u please help me. - sabari

1 Answers

1
votes

No need to store the current record. Use the unique identifier of the selected record in the Subform to select it, then use Docmd.RunSQL. Supposing the button is on your Mainform "Main" and the record in your subform "Sub" with the identifier "id":

    Dim sSQL as String
    sSQL = "DELETE FROM myTable WHERE id = " & Me!Sub!id
    DoCmd.RunSQL sSQL
    Me!Sub.Requery