Dynamic OCX Event does not fire
I have a custom built ocx, when the ocx is dragged onto a form and I trigger the Event it works but when I recreate the control with either early or late binding I cannot triiger the Event.
'Form version with ocx dragged onto form
Private Sub Command1_Click()
m_MyOcx.PerformOperation 9, 0
'This is a dummy operation that causes the Event to be fired.
End Sub
Private Sub m_MyOcx_OperationCompleted(ByVal nOperationID As Long, ByVal nExitCode As Long, ByVal nUserID As Long)
MsgBox "Fire!"
End Sub
The above works as intended.
Below does not work
Dim m_MyOcx As Object
Private Sub Command1_Click()
m_MyOcx.PerformOperation 9, 0
End Sub
Private Sub Form_Load()
Set m_MyOcx = CreateObject("MyOcx.MyOcx.1")
'Set m_MyOcx = New MyObjectName
End Sub
Private Sub m_MyOcx_OperationCompleted(ByVal nOperationID As Long, ByVal nExitCode As Long, ByVal nUserID As Long)
MsgBox "Fire!"
End Sub
I've also used late and early binding with no positive results.
Any help is appreciated.
Re: Dynamic OCX Event does not fire
Ok, I'm in a similar situation except that I'm using a VBControlExtender and it still doesn't work. Here's what the code looks like:
Project1.UserControl1:
VB Code:
Private WithEvents m_ctlDynamicDevice As VBControlExtender
Public Sub SomeSub()
Set m_ctlDynamicDevice = UserControl.Controls.Add("Project2.UserControl2", "DynDev")
End Sub
Private Sub m_ctlDynamicDevice_ObjectEvent(info As EventInfo)
If info.Name = "OnSomeEvent" then
'handle the event
End If
End Sub
Project2.UserControl2:
VB Code:
Event OnSomeEvent
Public Sub TriggerEvent
RaiseEvent OnSomeEvent
End Sub
I can step into the TriggerEvent routine, but when the event is raised, I can't step into the ObjectEvent routine. Also, UserControl.Controls.Add returns a valid object and that object does not change between the time its added and the time the event handler should be called.
1 Attachment(s)
Re: Dynamic OCX Event does not fire
See if the attached sample helps you.