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
        
        rs_DynObj.MoveNext
    Wend

Open in new window


Purpose:

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!

Wendee
error-2450.bmp
pwdellsAsked:
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)
0

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)

note:
just make sure that you use  the subform control name  

in the codes posted, i assume that the subform control name is "frmReqEntry"
0
Helen FeddemaCommented:
If so, that could cause confusion in code.  I recommend giving the subform the prefix "sub" ("frm" is a form prefix).
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

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

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"
0
pwdellsAuthor Commented:
On the property sheet, there is no attribute for NAME
properties.bmp
0
Rey Obrero (Capricorn1)Commented:

"select the All tab"
0
pwdellsAuthor Commented:
do you need a look further down?
properties-all.bmp
0
Rey Obrero (Capricorn1)Commented:
Look for the "Name" property
0
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
0
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.
0
pwdellsAuthor Commented:
I think it might be working.  I just need to go fix the other modules now.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.