How to Pass a Control Group as a Procedure Parameter

Posted on 2005-02-26
Medium Priority
Last Modified: 2010-05-02
I have a group of picture controls and command buttons on a form.  I need to pass the control groups to a Sub or Function.

This is my code:

ScanGroup me.picCards(), me.cmdPickOne

Sub ScanGroup(ppicCards() as PictureBox, pcmdPickOne() as Control)

Dim intCtr1 as integer

For intCtr1 to ppicCards.Count - 1
      If ppicCards(intctr) = pintCritical Then  
                  'Do something
                  Exit For
     End If
Next intCtr1

For intCtr1 to pcmdPickOne.Count - 1
     If pcmdPickOne(intctr) = pintCritical Then  
                  'Do something
                  Exit For
     End If
Next intCtr1

When I try to compile, I get a type mismatch error.  This comes from an incorrect parameters statement.

I can pass arrays with no problem.
What is different about control groups?
What am I doing wrong ?


Question by:Dovberman
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 13411185
(There are typos in your code.  I highly recommend you put Option Explicit at the top of your code.)

Anyhoo, pass the control arrays as Object:

Private Sub Command1_Click()
    ScanGroup Me.picCards, Me.cmdPickOne
End Sub

Sub ScanGroup(ppicCards As Object, pcmdPickOne As Object)
    Dim intCtr1 As Integer
    For intCtr1 = 0 To ppicCards.ubound
        If ppicCards(intCtr1) = pintCritical Then
            'Do something
            Exit For
        End If
    Next intCtr1

    For intCtr1 = 0 To pcmdPickOne.ubound
        If pcmdPickOne(intCtr1) = pintCritical Then
            'Do something
            Exit For
        End If
    Next intCtr1
End Sub

Author Comment

ID: 13412012
Your solution works fine.  The key was to refer to the control and picture box as objects.

I do use Option Explicit in all my code. Not shown in the snippet.

Thanks for the prompt reply.


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 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