I have been experimenting with adding controls at runtime. What I'm trying to do is connect to a db not knowing the structure of the db and field list; the db is user customizable, Build controls that will display the db fields. I therefore have an xml file with the field names from the db. The customization tool creates the xlm file. It also lets the user customize the presentation of the db. By reading the xml I know how many fields how to connect to the db and where to put the text boxes.
In a Form the following will work:
_________________________________________________________
'Start Creating Controls
'Add For loop to get all controls
For i = 0 To oNodes.length - 1
Set oNode = oNodes.Item(i)
strControlType = oNode.nodeName
strControlName = oNode.Attributes.Item(0).nodeTypedValue
'Parse control type to get control type ie textbox
'
'Create control
'*** This is the line that is not working *************
Me.Controls.Add strControlType, strControlName
'*******************************************************
Set oChildNodes = oNode.childNodes
With Me(strControlName)
.Visible = True
'Find property Values
For ic = 0 To oChildNodes.length - 1
Set oChildNode = oChildNodes.nextNode
If Not Left(oChildNode.nodeName, 1) = "#" Then
strAttName = oChildNode.nodeName
strAttValue = oChildNode.Text
' set properties of control
Select Case strAttName
Case "Height"
.Height = strAttValue
Case "Left"
.Left = strAttValue
Case "Top"
.Top = strAttValue
Case "Width"
.Width = strAttValue
Case "Text"
.Text = strAttValue
End Select
'end set properties
End If
Next
End With
Next
__________________________________________________________
I am acually opening up an xml doc and reading the values for the controls.
The problem is I was trying to convert this to a sstab on an activex control. There seems to be no controls collection in the userControl or on the ssTab control. Is that correct ?
What would be a better approch to solve the problem ?
Thanks,
Michael F. Zwijacz
In a Form the following will work:
_________________________________________________________
'Start Creating Controls
'Add For loop to get all controls
For i = 0 To oNodes.length - 1
Set oNode = oNodes.Item(i)
strControlType = oNode.nodeName
strControlName = oNode.Attributes.Item(0).nodeTypedValue
'Parse control type to get control type ie textbox
'
'Create control
'*** This is the line that is not working *************
Me.Controls.Add strControlType, strControlName
'*******************************************************
Set oChildNodes = oNode.childNodes
With Me(strControlName)
.Visible = True
'Find property Values
For ic = 0 To oChildNodes.length - 1
Set oChildNode = oChildNodes.nextNode
If Not Left(oChildNode.nodeName, 1) = "#" Then
strAttName = oChildNode.nodeName
strAttValue = oChildNode.Text
' set properties of control
Select Case strAttName
Case "Height"
.Height = strAttValue
Case "Left"
.Left = strAttValue
Case "Top"
.Top = strAttValue
Case "Width"
.Width = strAttValue
Case "Text"
.Text = strAttValue
End Select
'end set properties
End If
Next
End With
Next
__________________________________________________________
I am acually opening up an xml doc and reading the values for the controls.
The problem is I was trying to convert this to a sstab on an activex control. There seems to be no controls collection in the userControl or on the ssTab control. Is that correct ?
What would be a better approch to solve the problem ?
Thanks,
Michael F. Zwijacz