Delete Recordset NOT WORKING!

Randomblink

The Irreverent Reverend
Local time
Today, 07:02
Joined
Jul 23, 2001
Messages
279
Dim frm As Form, subfrm As Variant, sbfrm As SubForm, trgt As Object, rst As Recordset

Set frm = Form_mstrfrm_ProjectBasics
Set sbfrm = frm!subfrmData_CCFN
Set trgt = sbfrm!CCFN_No
subfrm = sbfrm.SourceObject
Set rst = subfrm.Recordset
rst.Delete

The line: subfrm = sbfrm.SourceObject is a string...
So I get type mismatch on the next line...

What do I need to do?

I am trying to:
Create a popup menu that will delete the current record.
The current record is on a subform on a form.
HELP ME!

Please
 
You are probably having the error because you need to use the RecordsetClone property instead of Recordset.

Set rst = subfrm.Recordset

Should be:

Set rst = subfrm.RecordsetClone


But I don't think this will get you exactly what you want. It looks like your code will always delete the first record in the recordset.

Does your subform rowsource have a unique key? Then you can use an SQL Delete statement to delete the current row:

DoCmd.Runsql "Delete from MyTable Where MyIDField = " & Forms!MyFormName!MySubformControlName.form!MyIDField & ";"

Hope this helps,
 

Users who are viewing this thread

Back
Top Bottom