• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

How to pass a Control to a Sub?

I have an ActiveX control that I can drag and drop onto a form. It has no way to create the object on the fly, rather it must be dragged and dropped onto the form. It is a third party object.  I need 10 instances of this control, so I have dragged 10 of them on to my form. They are called x1, x2, x3, etc.

I now have set the various properties to values such as:
x1.Color = vbRed
x1.Speed = 1
x2.Color = vbBlack
x2.Speed = 5

How do I pass these objects to a function to set the properties?  I want to do something like this:

Call SetProperties( x1, vbRed, 1 )
Call SetProperties( x2, vbBlack, 5)

I tried:
Public Sub SetProperties( MyObj as Object)   but it does not allow me to access the properties.

I tried:
Public Sub SetProperties( MyObj as Control)   but it does not allow me to access the properties either.

Thank you.

1 Solution
Simply set the "as" property in your Sub to the same name as the Control name you dragged onto your form. You should see it listed in the drop down box after you type the "as".  It will then allow you to access the properties.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now