Search code examples
vbams-access-2013subform

Referencing all records in a subform?


Is there a way to loop through all records in a subform without having to reference the specific query used to populate the subform? I'm trying to go without the whole

Dim db As Database
Dim rs As Recordset
Dim strQuery As String

Set db = CurrentDb
strQuery = [some query]
Set rs = db.OpenRecordset(strQuery)

declaration since it increases load time (I have 7-30 subforms on my form).

Something like

'Part of method within the subform, not main form
Dim rs As Recordset
rs = Form.Recordset

Would be nice (except the example above doesn't work).

Thanks!


Solution

  • Dim rs As Recordset
    set rs = me.Recordset
    

    should work: you forgot the Set

    In older versions of Access, use:

    set rs = me.recordsetClone