By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 2,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

Is indirect sub/function possible in Access?

P: n/a
Is it possible to call a subroutine or function whose name is in a
string?
Nov 12 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Why make life any more complicated than it is?

What could be simpler than:
Call MySubroutine
or
MyFunction(MyParameter)
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
www.pcdatasheet.com
"dchow" <dc***@hotmail.com> wrote in message
news:i2********************************@4ax.com...
Is it possible to call a subroutine or function whose name is in a
string?

Nov 12 '05 #2

P: n/a
"dchow" <dc***@hotmail.com> wrote in message
news:i2********************************@4ax.com...
Is it possible to call a subroutine or function whose name is in a
string?

I can't imagine why anyone want might to do this. I have never felt the
need to do so. Is there a particular problem you are trying to overcome?
If you thought it would bring any advantage, you could write something like
this in a new module:
Public Sub DoSomething(strWhat As String)
Select Case strWhat
Case "One": Call One
Case "Two": Call Two
Case "Three": Call Three
Case Else: MsgBox "I don't know what to do"
End Select
End Sub

Private Sub One()
MsgBox "One"
End Sub

Private Sub Two()
MsgBox "Two"
End Sub

Private Sub Three()
MsgBox "Three"
End Sub

Fletcher

Nov 12 '05 #3

P: n/a
DC -

See the 'Eval Function' topic in Access Help.

- Brian

-- In article <i2********************************@4ax.com>,
dc***@hotmail.com says...
Is it possible to call a subroutine or function whose name is in a
string?

Remove NOSPAM to reply...
Nov 12 '05 #4

P: n/a
You can go:

dim strFun as string
strFun = "FunctionTest()"

Eval (strFun)
--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
ka****@msn.com
http://www.attcanada.net/~kallal.msn
Nov 12 '05 #5

P: n/a
Hi Fletcher,

I have used it in one app. The circumstances were the database would
perform a certain operation on start-up eg log a users C: Drive using a
batch file and copy tree or some other operation/s depending on the
timing etc.

I stored this inforamtion in a backend table and the front end ran a
query each time to see what operation needed to be performed.

Because the app didn't know if it was going to get a batch file path or
in some cases a function name I used eval. This meant I could store and
manipulate all the operations from one table on the file server - however
yes the function/sub had to be in the front end.

Really I just wanted to be able to control it all from one table and one
controlling function.

Peter

"Fletcher Arnold" <fl****@home.com> wrote in
news:bm**********@hercules.btinternet.com:
"dchow" <dc***@hotmail.com> wrote in message
news:i2********************************@4ax.com...
Is it possible to call a subroutine or function whose name is in a
string?
I can't imagine why anyone want might to do this.

Fletcher


Nov 12 '05 #6

P: n/a
fl****@home.com (Fletcher Arnold) wrote in
<bm**********@hercules.btinternet.com>:
"dchow" <dc***@hotmail.com> wrote in message
news:i2********************************@4ax.com.. .
Is it possible to call a subroutine or function whose name is in
a string?

I can't imagine why anyone want might to do this. I have never
felt the need to do so.


I have a standard component in many of my apps that have large
numbers of reports. I call it a "report switchboard," and it
consists of an option group (for type of report), a listbox
(listing the reports for a type) and text field (for the verbose
description of the report). It's driven by a data table.

In that data table, there are three fields that are operated on to
open the report, depending on what type of report it is. Those
fields are:

ReportName
ReportForm
ReportFunction

Only one of these three fields is allowed to be filled out, and the
non-null one gets executed. The code for the first two fields is
quite simple, just DoCmd.OpenReport or DoCmd.OpenForm, but the
latter requires the Eval().

And it's a very useful thing to have for this context.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #7

P: n/a
"Fletcher Arnold" <fl****@home.com> wrote in message
news:bm**********@hercules.btinternet.com...
"dchow" <dc***@hotmail.com> wrote in message
news:i2********************************@4ax.com...
Is it possible to call a subroutine or function whose name is in a
string?


Thanks for the ideas Peter & David. I can't see a current need for it in
any of my projects, but your uses of the Eval function seem to make good
sense.

Fletcher
Nov 12 '05 #8

P: n/a
This is exactly what I was trying to do. I was using a table for a
function despatcher. The table contains 2 fields, a type and a name.
Type can be "qry", "frm" or "fnc". Depending on the type I would call
docmd.OpenQuery, OpenForm or call the function.
Thanks
On Mon, 13 Oct 2003 18:21:55 GMT, dX********@bway.net.invalid (David
W. Fenton) wrote:
fl****@home.com (Fletcher Arnold) wrote in
<bm**********@hercules.btinternet.com>:
"dchow" <dc***@hotmail.com> wrote in message
news:i2********************************@4ax.com. ..
Is it possible to call a subroutine or function whose name is in
a string?

I can't imagine why anyone want might to do this. I have never
felt the need to do so.


I have a standard component in many of my apps that have large
numbers of reports. I call it a "report switchboard," and it
consists of an option group (for type of report), a listbox
(listing the reports for a type) and text field (for the verbose
description of the report). It's driven by a data table.

In that data table, there are three fields that are operated on to
open the report, depending on what type of report it is. Those
fields are:

ReportName
ReportForm
ReportFunction

Only one of these three fields is allowed to be filled out, and the
non-null one gets executed. The code for the first two fields is
quite simple, just DoCmd.OpenReport or DoCmd.OpenForm, but the
latter requires the Eval().

And it's a very useful thing to have for this context.


Nov 12 '05 #9

P: n/a
I tried the following but it didn't work. I didn't know what was
wrong.

Private Function fncTest()
MsgBox "Test subroutine"
End Function

Sub test()
Dim strFun As String

strFun = "fncTest()"
Eval (strFun)
End Sub

The error was "The expression you entered has a function name that
Microsoft Access can't find"

If I did
Eval(fncTest())
then it worked.

But I need the function name to be in a string variable.
On Mon, 13 Oct 2003 04:29:02 GMT, "Albert D. Kallal" <ka****@msn.com>
wrote:
You can go:

dim strFun as string
strFun = "FunctionTest()"

Eval (strFun)


Nov 12 '05 #10

P: n/a
Sorry, I found the problem. It was because my test function was
Private.

On Wed, 15 Oct 2003 15:27:43 -0700, dchow <dc***@hotmail.com> wrote:
I tried the following but it didn't work. I didn't know what was
wrong.

Private Function fncTest()
MsgBox "Test subroutine"
End Function

Sub test()
Dim strFun As String

strFun = "fncTest()"
Eval (strFun)
End Sub

The error was "The expression you entered has a function name that
Microsoft Access can't find"

If I did
Eval(fncTest())
then it worked.

But I need the function name to be in a string variable.
On Mon, 13 Oct 2003 04:29:02 GMT, "Albert D. Kallal" <ka****@msn.com>
wrote:
You can go:

dim strFun as string
strFun = "FunctionTest()"

Eval (strFun)


Nov 12 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.