Accessing controls dynamically in a sub form.

My Code:

    str_DynObj = _
            "SELECT tbx_DynamicObjects.Object, tbx_DynamicObjects.Pos1_TopTwips, " & _
                "tbx_DynamicObjects.Pos2_TopTwips, tbx_DynamicObjects.FormID, " & _
                "tbx_DynamicObjects.TabID, tbx_DynamicObjects.Active " & _
            "FROM tbx_DynamicObjects " & _
            "WHERE tbx_DynamicObjects.FormID = 22 " & _
                "AND tbx_DynamicObjects.TabID = 3 " & _
                "AND tbx_DynamicObjects.Active = TRUE "
    Set rs_DynObj = db.OpenRecordset(str_DynObj)
    While Not rs_DynObj.EOF
        Forms("frmReqEntry").Controls(rs_DynObj.Fields(0)).Top = rs_DynObj.Fields(1)
        Forms("frmReqEntry").Controls(rs_DynObj.Fields(0)).Visible = True

Open in new window


I pull attributes like TOP and VISIBLE, etc from the database table tbx_DynamicObjects.  Form: frmReqEntry works great independently.  But I have a Master Form frmMain that pulls frmReqEntry (and others alike) in as a subform.  Once I try to access this frmReqEntry via the Master Form, I get the error below:

Any Ideas?

Thanks in Advance!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
you access the subform from the main form with

Forms("NameOfForm")("frmReqEntry").Form.Controls(rs_DynObj.Fields(0)).Top = rs_DynObj.Fields(1)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:
if the code is run from the main form module

me.frmReqEntry.Form.Controls(rs_DynObj.Fields(0)).Top = rs_DynObj.Fields(1)

just make sure that you use  the subform control name  

in the codes posted, i assume that the subform control name is "frmReqEntry"
Helen FeddemaCommented:
If so, that could cause confusion in code.  I recommend giving the subform the prefix "sub" ("frm" is a form prefix).
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Helen FeddemaCommented:
Then frmReqEntry would be the source object of subReqEntry
pwdellsAuthor Commented:
I get the same error when I run:

Forms("frmMain")("frmReqEntry").Form.Controls(rs_DynObj.Fields(0)).Top = rs_DynObj.Fields(1)
Rey Obrero (Capricorn1)Commented:

open the main form in design view
select the Outer edge of the subform and hit F4
select the All tab
look what is displayed in the "Name" property  

get that "Name" value and use it in place of  "frmReqEntry"
pwdellsAuthor Commented:
On the property sheet, there is no attribute for NAME
Rey Obrero (Capricorn1)Commented:

"select the All tab"
pwdellsAuthor Commented:
do you need a look further down?
Rey Obrero (Capricorn1)Commented:
Look for the "Name" property
Rey Obrero (Capricorn1)Commented:
and i think you are looking at the wrong property sheet

you should be seing

Subform/Subreport :

at the title bar
pwdellsAuthor Commented:
frm_Subject is what comes up when I click on the top.  I was getting just FORM when I clicked on the side.

So I will try frm_Subject now.
pwdellsAuthor Commented:
I think it might be working.  I just need to go fix the other modules now.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.