|
-
Feb 26th, 2004, 04:56 PM
#1
Thread Starter
Hyperactive Member
Referencing ActiveX control from module
When I add a module to my ActiveX control,
I am trying to reference my ActiveX control from my module..
i.e
UserControl.CommonDialog ....
But I always get the error, UserControl is not defined, when that is definately the name of the control.
what am I doing wrong
-
Feb 26th, 2004, 05:34 PM
#2
You need to pass a reference to the current instance into the module procedure. The module has no way of knowing what instance of your control you are referring to since it is shared across all instances, so you need to tell it.
Example
VB Code:
'UserControl
Public Sub DoSomething()
Call mDoSomething(Me)
End Sub
'Module
Pubic Sub mDoSomething(c As YourUserControl)
c.SomeProperty = SomeValue
End Sub
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Feb 27th, 2004, 04:54 AM
#3
Thread Starter
Hyperactive Member
Hi,
I tried that, but then I get the error, type mismatch on the line
Call FileOpenProc(Me)
Here is my code...
' UserControl code
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "Open"
CallFileOpenProc
End Select
End Sub
Public Sub CallFileOpenProc()
Call FileOpenProc(Me)
End Sub
' Module
Sub FileOpenProc(uc As UserControl)
' Do something here...
uc.CommonDialog1.DialogTitle = "Open"
End Sub
-
Feb 27th, 2004, 07:47 AM
#4
Don't reference it as UserControl, reference it by the type name you gave it.
VB Code:
' UserControl code
Public Property Get Controls() As Object '<-- Very important
Set Controls = UserControl.Controls
End Property
Public Sub CallFileOpenProc()
Call FileOpenProc(Me)
End Sub
' Module code
Sub FileOpenProc(uc As [i]MyUserControl[/i])
' Do something here...
uc.Controls("CommonDialog1").DialogTitle = "Open"
End Sub
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Feb 27th, 2004, 11:11 AM
#5
Thread Starter
Hyperactive Member
Thanks, that works perfectly!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|