Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Call Subroutine as variable (Access 2003)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WC Justice - 22 Oct 2006 20:11 GMT
I would like to be able to call a particular subroutine based on recordset
data.

For example, if rs.fields("FormID") = 29, I would like to be able to call
PreviewDocument29 by doing something like this:  

strSubName = "PreviewDocument" & rs.fields("FormID")
call strSubName

I am currently doing it the crude way:

if rs.fields("FormID") = 1 then
call PreviewDocument1
elseif rs.fields("FormID") = 2 then
call PreviewDocument2
...
end if

If strSubName needs to be an object of some sort, I don't know what it needs
to be.  Any help would be appreciated.
Jezebel - 22 Oct 2006 22:27 GMT
You can use CallByName(), although even the MS developers warn that's a
horribly slow method.

>I would like to be able to call a particular subroutine based on recordset
> data.
[quoted text clipped - 17 lines]
> needs
> to be.  Any help would be appreciated.
WC Justice - 22 Oct 2006 23:52 GMT
Speed is not enough of an issue to keep me from using it to address my issue.
However, from looking into the CallByName function, I don't see how to use
it to call a subroutine.  I also failed to mention that the subroutine
contains an argument.

> You can use CallByName(), although even the MS developers warn that's a
> horribly slow method.
Tony Jollans - 23 Oct 2006 00:00 GMT
I wouldn't recommend this in this circumstance (what is wrong with a simple
Select Case statement?) but one relatively simple way to do it is ...

In ThisDocument put ...

   Sub PreviewDocument1(Argument)
       ' Do whatever
   End Sub

   Sub PreviewDocument2(Argument)
       ' Do whatever
   End Sub

   ' etc.

Wherever you want it, code

   Callbyname ThisDocument, "PreviewDocument" & rs.fields("FormID"),
vbMethod, Parameter

--
Enjoy,
Tony

> Speed is not enough of an issue to keep me from using it to address my issue.
>  However, from looking into the CallByName function, I don't see how to use
[quoted text clipped - 3 lines]
> > You can use CallByName(), although even the MS developers warn that's a
> > horribly slow method.
Cindy M. - 26 Oct 2006 10:45 GMT
Hi =?Utf-8?B?V0MgSnVzdGljZQ==?=,

> would like to be able to call a particular subroutine based on recordset
> data.
[quoted text clipped - 4 lines]
> strSubName = "PreviewDocument" & rs.fields("FormID")
> call strSubName

You might try Application.Run strSubName

(BTW, this group is specific for Microsoft WORD, not Access.)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.