473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Is indirect sub/function possible in Access?

Is it possible to call a subroutine or function whose name is in a
string?
Nov 12 '05 #1
10 7636
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
"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
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
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
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
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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Hal Vaughan | last post by:
I'm not sure what the correct name for this would be. I'd think it's either an indirect reference, or a pointer, or something like that. I'm working on a program that would call a series of...
1
by: Johnny Funder | last post by:
Hi, I'm working on a GUI using many textfields. Which textfield to put data into depends on data received via a telnet session. To avoid doing a huge block of if/else if/else if I wondered if it...
1
by: suresh | last post by:
Namasivayah, Stroustrup says when indirect array is used for reordering a valarray the index cannot be repeated twice(page 679). But Nicolai Josuttis in his book on C++ standard library, page...
1
by: James | last post by:
I am looking for a way to delete indirect children records when a root record is removed. The same action that occurs if you delete a directory that contains sub directories of sub directories. ...
1
by: Sam Phillips | last post by:
Howdy, I'm trying to apply color schemes to forms and subforms. I'm using a global function to change the colors/fonts of controls. Right now it correctly loops over the controls in the main...
13
by: ganeshb | last post by:
Hi, What C statement(s) would translate to indirect jmp in assembly? I know that function pointer invocation would translate to indirect 'call' instruction, but I am not sure what will lead to...
8
by: Gaetan | last post by:
Is is possible in C# to have the equivalent of an array of function pointers in C? I have a situation where a top level class exposes methods like Add, Delete, ... and a few child classes with...
2
by: Zioth | last post by:
class A { function Get() {return $this;} } $obj = new A(); In php5, the following statement is valid: $x = $obj->Get()->Get(); In php4, I get the following error:
5
by: Rahul B | last post by:
Hi, I am having the following issues while trying to restrict the current user from creating any objects. Below is the privileges for the user and response when i try to create a table in that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.