G
GTajos
I am trying to access the Recordset of a subform from a module (not with in
the main form nor the subform)
If this has been answered before please forgive me. I did spend 40 minutes
digging for this answer.
Sub debugGetDSrs()
Dim Frm As Form, SubFrm As Form, SubFrmCtrl As Control, RS As Recordset, fld
As Field
Set Frm = Forms("CR_Frm")
Set SubFrmCtrl = Frm.Controls("CR_DS")
Debug.Print SubFrmCtrl.SourceObject 'This returns "CR_DataSheet" as it should
Debug.Print SubFrmCtrl.Form.Name 'This returns "CR_DataSheet" as it should
Debug.Print SubFrmCtrl.Form.Recordset.RecordCount 'This returns "2022" as
it should
Set RS = SubFrmCtrl.Form.Recordset 'This Errors with a type mismatch
For Each fld In RS.Fields
Debug.Print fld.Name
Next
Set RS = Nothing
Set SubFrmCtrl = Nothing
Set Frm = Nothing
End Sub
The Main Form Name is "CR_Frm"
The name of the control that contians the subform is "CR_DS"
The subform name is "CR_DataSheet"
Thanks,
Garry
the main form nor the subform)
If this has been answered before please forgive me. I did spend 40 minutes
digging for this answer.
Sub debugGetDSrs()
Dim Frm As Form, SubFrm As Form, SubFrmCtrl As Control, RS As Recordset, fld
As Field
Set Frm = Forms("CR_Frm")
Set SubFrmCtrl = Frm.Controls("CR_DS")
Debug.Print SubFrmCtrl.SourceObject 'This returns "CR_DataSheet" as it should
Debug.Print SubFrmCtrl.Form.Name 'This returns "CR_DataSheet" as it should
Debug.Print SubFrmCtrl.Form.Recordset.RecordCount 'This returns "2022" as
it should
Set RS = SubFrmCtrl.Form.Recordset 'This Errors with a type mismatch
For Each fld In RS.Fields
Debug.Print fld.Name
Next
Set RS = Nothing
Set SubFrmCtrl = Nothing
Set Frm = Nothing
End Sub
The Main Form Name is "CR_Frm"
The name of the control that contians the subform is "CR_DS"
The subform name is "CR_DataSheet"
Thanks,
Garry