Article ID: 188577
Article Last Modified on 5/13/2003
Private Sub UserControl_Initialize()
UserControl.BackColor = vbBlue
End Sub1
Option Explicit
' create an object reference so a control can be dynamically loaded
' during run-time.
Private ctlMyTestControl As VBControlExtender
Private Sub Command1_Click()
' The test control will be loaded without its design-time license
' first. This will result in an error that will be trapped or
' reported in a MSGBOX.
On Error GoTo NoLicense
' load the test control dynamically.
Set ctlMyTestControl = Form1.Controls.Add("Project1.UserControl1", _
"ctlTest")
' show the test control.
ctlMyTestControl.Visible = True
' exit this function.
Exit Sub
NoLicense:
' make sure the error is about the license for this control.
If Err.Number = 731 Then
MsgBox "You need a License to dynamically load this ActiveX" & _
& " control"
End If
End Sub
Private Sub Command2_Click()
' add the license of the test ActiveX control to the
' running application and then dynamically load the
' control.
Licenses.Add "Project1.usercontrol1"
' load the test control dynamically.
Set ctlMyTestControl = Form1.Controls.Add("Project1.UserControl1", _
"ctlTest")
' show the test control.
ctlMyTestControl.Visible = True
End Sub
Additional query words: kbDSupport kbdss kbCtrl kbCtrlCreate kbVBp600 kbVBp
Keywords: kbhowto KB188577