Results 1 to 5 of 5

Thread: Referencing ActiveX control from module

  1. #1

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366

    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

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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:
    1. 'UserControl
    2. Public Sub DoSomething()
    3.     Call mDoSomething(Me)
    4. End Sub
    5.  
    6. 'Module
    7. Pubic Sub mDoSomething(c As YourUserControl)
    8.     c.SomeProperty = SomeValue
    9. End Sub
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    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

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Don't reference it as UserControl, reference it by the type name you gave it.
    VB Code:
    1. ' UserControl code
    2. Public Property Get Controls() As Object '<-- Very important
    3.     Set Controls = UserControl.Controls
    4. End Property
    5.  
    6. Public Sub CallFileOpenProc()
    7.     Call FileOpenProc(Me)
    8. End Sub
    9.  
    10. ' Module code
    11. Sub FileOpenProc(uc As [i]MyUserControl[/i])
    12.     ' Do something here...
    13.     uc.Controls("CommonDialog1").DialogTitle = "Open"
    14. End Sub
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    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
  •  



Click Here to Expand Forum to Full Width