Passing  control name to fucntion!?

Posted on 2004-11-02
Last Modified: 2010-05-02
Hi all,

 I'm wondering if it's posible to pass the name of the control to a function:
eg: I have a 3 Msflexgrid's - Msflexgrid1(1 rows, 3cols),Msflexgrid2(4 rows, 3cols),Msflexgrid3(2 rows, 3cols). When click on a button I'm calling a funtion which will do some calculation involving these 3 grids.
My question is, can I send the name of the controls (Msflexgrid1,2,3) and use them trhough the function?

Question by:rod69
    LVL 48

    Expert Comment

    LVL 32

    Accepted Solution

    In your form, use this

    Call MyFunction(Me.MsFlexGrid1)

    'And in your module, your function is declared like this...

    Public Function MyFunction(grid As MsFlexGrid)
        With grid
        'and so on
        End With

    End Function
    LVL 5

    Expert Comment


    call MyFunction(me.myGrid)

    Public function functionname(grid as control)

    LVL 32

    Expert Comment


    You can test for a specific name like this:

    Public Function MyFunction(grid As MsFlexGrid)
        Select Case grid.Name

        Case "MsFlexGrid1"

    LVL 48

    Expert Comment

    dan shouldnt  Callbyname be suffice

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    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…

    729 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

    19 Experts available now in Live!

    Get 1:1 Help Now