how do i call a function by using the function name as a string of characters 
Author Message
 how do i call a function by using the function name as a string of characters

I have a form with 20 checkboxes.
Each checkbox is associated with a report.
The TAG property for each checkbox is the name of a function that calls the
report to be run.
The user is able to check off any number of reports.
When he hits the "Run Reports" button, the code loops thorugh all the
controls on the form, checks to see if the checkbox is checked and then
calls the function to run the report.  The report calling code is actually
located in a function in another module.  Each report has it's own function
that runs it.  This is done because these reports can be called from many
different places and have quite a bit of code that runs prior to the running
of each specific report.
Here's the problem.  How do you call a function in the following manner?

    Dim ctl As Control
    Dim i As Integer

    For i = 0 To (Me.Count - 1)
        Set ctl = Me(i)
        If Me(i).ControlType = acCheckBox Then
            If Me(i) = True Then
                    'This doesn't work:  Call ctl.Tag & "()"     ' where
ctl.Tag = MyFunction
                    'This doesn't work either:  Application.Run ctl.Tag &
"()"
                End If
            End If
        End If
    Next i

Any ideas on how to do this?

Thanks,

Keith



Sun, 30 Jul 2006 12:46:37 GMT  
 how do i call a function by using the function name as a string of characters

Quote:

>I have a form with 20 checkboxes.
>Each checkbox is associated with a report.
>The TAG property for each checkbox is the name of a function that calls the
>report to be run.
>The user is able to check off any number of reports.
>When he hits the "Run Reports" button, the code loops thorugh all the
>controls on the form, checks to see if the checkbox is checked and then
>calls the function to run the report.  The report calling code is actually
>located in a function in another module.  Each report has it's own function
>that runs it.  This is done because these reports can be called from many
>different places and have quite a bit of code that runs prior to the running
>of each specific report.
>Here's the problem.  How do you call a function in the following manner?

>    Dim ctl As Control
>    Dim i As Integer

>    For i = 0 To (Me.Count - 1)
>        Set ctl = Me(i)
>        If Me(i).ControlType = acCheckBox Then
>            If Me(i) = True Then
>                    'This doesn't work:  Call ctl.Tag & "()"     ' where
>ctl.Tag = MyFunction
>                    'This doesn't work either:  Application.Run ctl.Tag &
>"()"
>                End If
>            End If
>        End If
>    Next i

As long as the things you want to call are a Public Function
in a standard module, you can use the Eval function:

        xx = Eval(ctl.Tag & "()")
--
Marsh
MVP [MS Access]



Sun, 30 Jul 2006 13:05:49 GMT  
 how do i call a function by using the function name as a string of characters
I thought of that but didnt' think it would work.  Guess I should have tried
it first!  Thanks :)


Quote:

> >I have a form with 20 checkboxes.
> >Each checkbox is associated with a report.
> >The TAG property for each checkbox is the name of a function that calls
the
> >report to be run.
> >The user is able to check off any number of reports.
> >When he hits the "Run Reports" button, the code loops thorugh all the
> >controls on the form, checks to see if the checkbox is checked and then
> >calls the function to run the report.  The report calling code is
actually
> >located in a function in another module.  Each report has it's own
function
> >that runs it.  This is done because these reports can be called from many
> >different places and have quite a bit of code that runs prior to the
running
> >of each specific report.
> >Here's the problem.  How do you call a function in the following manner?

> >    Dim ctl As Control
> >    Dim i As Integer

> >    For i = 0 To (Me.Count - 1)
> >        Set ctl = Me(i)
> >        If Me(i).ControlType = acCheckBox Then
> >            If Me(i) = True Then
> >                    'This doesn't work:  Call ctl.Tag & "()"     ' where
> >ctl.Tag = MyFunction
> >                    'This doesn't work either:  Application.Run ctl.Tag &
> >"()"
> >                End If
> >            End If
> >        End If
> >    Next i

> As long as the things you want to call are a Public Function
> in a standard module, you can use the Eval function:

> xx = Eval(ctl.Tag & "()")
> --
> Marsh
> MVP [MS Access]



Sun, 30 Jul 2006 13:19:39 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Executing Function using String Containing Function Name

2. Calling function or sub with variable array or string names

3. Call function by name as a string

4. Call Module Function using string value

5. Calling functions/subs using the string title - possible?

6. Call function using strings

7. Using String/Text type functions within functions that requires cell references

8. Help with using names and variables in a function call

9. Call Function using Func Name stored in variable

10. Using Format function inside User Defined Function changes function value


 
Powered by phpBB® Forum Software © phpBB Group