I am trying to access a value within a continuous form, and then pass that to a new form that is opened. I got this working properly, but it only works if the original form is open directly. It fails if I try and run this when the form is embedded within another form.
The error I get is;
Run-Time error '2450': MS access cannot find the referenced 'ViewerForm'
The code I am using is; (courtesy of here: Get Control or Recrdset Value on Continous Form)
Dim r As DAO.Recordset
Set r = Forms![ViewerForm].RecordsetClone 'Clone the recordset
r.Bookmark = Forms![ViewerForm].Bookmark 'Navigate to the active record
Myvalue = r!TagMain.Value
Why does the code work when I am opening the form by itself, yet fails when it is embedded within another form? Do I have to tell it the path through, to find the embedded form, such as
Forms![FormTheViewerIsEmbeddedWithin]![ViewerForm].RecordsetClone
Instead of
Forms![ViewerForm].RecordsetClone
CodePudding user response:
ViewerForm
is the subform control on the main form. The control has no RecordsetClone
.
You need the (sub)form that's inside it:
Forms![FormTheViewerIsEmbeddedWithin]![ViewerForm].Form.RecordsetClone
If you get the error MS access cannot find the referenced 'ViewerForm'
, your subform control has a different name than the subform. Check its properties in the main form.