How to pass a Control to a Sub?

Posted on 2005-04-20
Last Modified: 2010-05-02
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.

Question by:deming
    1 Comment
    LVL 3

    Accepted 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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now