Naming dynamically created controls on imported userforms

CodeMonkey01

New Member
Joined
Jul 21, 2011
Messages
6
A colleague and I are building a template builder, which reads data from an XML, opens a new workbook, imports a number of pre-coded modules and userform(s), then dynamically adds buttons and labels to the userform, complete with event handlers. We've gotten 99% of it to work, but we cannot name our dynamically-created controls. For instance:

Code:
With wbProject.VBProject.VBComponents
        '--Load the list of nodes we want to loop through
        Set ufMain = .Item("ufMain")
        Set frmSummary = ufMain.Designer.Controls.Item("frmSummary")
 
        Set xmlNodeList = JOBXML.SelectNodes("/JobProcessingInstructions/LoanHeaders/LoanHeader")
For Each xmlNode In xmlNodeList
            '--Retrieve the label value from the xml
            strLoanHeader = xmlNode.Attributes.getNamedItem("Value").nodeTypedValue
            Set lblHeading = frmSummary.Controls.Add("Forms.Label.1") ', "lbl" & strLoanHeader & "Heading")
            With lblHeading
                .Name = "lbl" & strLoanHeader & "Heading"
                .Top = 12 + (iRows * 18)

The compiler blows up on the .name line with this message:

Run-time error '40044':

Could not set the Name property. Could not complete the operation due to error 800a9c6c.

Google has failed me in regard to that error number (800a9c6c). Thus far, I have been unable to use ufMain.Controls(lblHeading.Name).Properties("Name") = TextString, either, as the compiler says the object doesn't support this property or method.

Does anyone know how I can set a name for my controls that are created this way? We've determined workarounds for this, but it's going to be a big pain and may not work in the future; this project builder is intended to be available to non-programmers who can edit an XML in the future.

I am working in Excel 2007.

Thank you in advance for any assistance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top