Can't refer to a subform

  • Thread starter Thread starter Andy Korth
  • Start date Start date
A

Andy Korth

Well, I liked that code that Elwin and Andy Cole wrote
for me so much that i decided to use it in a couple other
places.
I want to do some recordset stuff with a subform, but I
get an error saying the form cannot be found.

Set rst = Forms![Plots by Operation
subform].RecordsetClone
is the line that gives the error.

In another situation, I have this working code:
Set rst = Me.RecordsetClone

The form name is spelled correctly. Is the problem
occuring because the form is already open as a subform in
the form that is calling this command?
If not, how can I accomplish this? (full code is below)

Thanks in advance,
Andy

Dim arrPlots(194) As Integer
Dim CountedRecs As Integer
Dim rst As DAO.Recordset
Dim intI As Integer
Set rst = Forms![Plots by Operation
subform].RecordsetClone 'error...
With rst
.MoveLast
.MoveFirst
CountedRecs = .RecordCount
For intI = 1 To CountedRecs
arrPlots(intI - 1) = ![Plot]
.MoveNext
Next intI
End With
rst.Close
Set rst2 = Nothing
 
The form name is spelled correctly. Is the problem
occuring because the form is already open as a subform in
the form that is calling this command?

Yes. A Subform is not open in its own right, and is not part of the
Forms collection.

You need the Name property *of the Subform control* containing the
form - it's often but not necessarily the same as the name of the form
therein. The syntax would be:

Set rs = Forms!mainformname!subformcontrol.Form.RecordsetClone
 
Back
Top