?
Solved

Accessing controls dynamically in a sub form.

Posted on 2011-10-26
13
Medium Priority
?
328 Views
Last Modified: 2012-06-27

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
0
Comment
Question by:pwdells
  • 6
  • 5
  • 2
13 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 37033966
you access the subform from the main form with

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

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37033995
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
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 37034143
If so, that could cause confusion in code.  I recommend giving the subform the prefix "sub" ("frm" is a form prefix).
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 31

Expert Comment

by:Helen Feddema
ID: 37034147
Then frmReqEntry would be the source object of subReqEntry
0
 

Author Comment

by:pwdells
ID: 37038344
I get the same error when I run:

Forms("frmMain")("frmReqEntry").Form.Controls(rs_DynObj.Fields(0)).Top = rs_DynObj.Fields(1)
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37038407
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
 

Author Comment

by:pwdells
ID: 37038468
On the property sheet, there is no attribute for NAME
properties.bmp
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37038588

"select the All tab"
0
 

Author Comment

by:pwdells
ID: 37038662
do you need a look further down?
properties-all.bmp
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37038757
Look for the "Name" property
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37038784
and i think you are looking at the wrong property sheet

you should be seing

Subform/Subreport :

at the title bar
0
 

Author Comment

by:pwdells
ID: 37038799
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
 

Author Comment

by:pwdells
ID: 37038817
I think it might be working.  I just need to go fix the other modules now.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question