PC Review


Reply
Thread Tools Rate Thread

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

 
 
Keith G Hicks
Guest
Posts: n/a
 
      11th Feb 2004
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


 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      11th Feb 2004
Keith G Hicks wrote:

>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]
 
Reply With Quote
 
Keith G Hicks
Guest
Posts: n/a
 
      11th Feb 2004
I thought of that but didnt' think it would work. Guess I should have tried
it first! Thanks

"Marshall Barton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Keith G Hicks wrote:
>
> >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]



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
call function from string var Pendragon Microsoft Access VBA Modules 2 28th Dec 2008 01:57 AM
String function to replace characters =?Utf-8?B?U3RldmVJbkJlbG9pdA==?= Microsoft Access Form Coding 3 22nd Sep 2005 05:01 PM
Call function by name as a string Jonathan Scott via AccessMonster.com Microsoft Access Form Coding 7 19th Aug 2005 08:08 AM
String Function 'Like' and Special Characters Vagabond Software Microsoft Excel Programming 3 12th Jun 2004 02:02 AM
Re: Excel4 Call to get Function String Rob Bovey Microsoft Excel Programming 6 24th Sep 2003 06:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:16 AM.