473,387 Members | 1,572 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,387 software developers and data experts.

how can i call a private sub using a variable that contains the name of the sub?

2
Private Sub cmdProcessEvents_Click()
strEventID = "Audit0001"

'This works:
Audit0001

'These do not:
Eval (strEventID)
Application.Run strEventID

End Sub

Private Sub Audit0001()
MsgBox "Here i am"
End Sub
Feb 19 '10 #1

✓ answered by vb5prgrmr

Not sure it is possible with a private sub but you might get it working with callbyname function... doubt it,... but


Good Luck

4 3410
vb5prgrmr
305 Expert 100+
Not sure it is possible with a private sub but you might get it working with callbyname function... doubt it,... but


Good Luck
Feb 20 '10 #2
yarbrough40
320 100+
If you find an answer to this on your own, please post it. I would also love to know how to do this as well....
Feb 20 '10 #3
Reg9
2
This worked for me!
Thank you vb5prgrmr very much for your suggestion!
The code that i got to work is listed below.

For others who may want to do this, here are some points to be aware of:

1 I did quite a bit of searching before posting my own question. Other people seemed to be satisfied when they were pointed to Eval or Application.Run. I do not know why these worked for others and not for me. Therefore, i do not know under what circumstances they might be a better choice.

2 I am working in Access 2003 VBA within a Form Module.

3 In order to get CallByName to work, i had to change the subroutine from Private to Public, even though it is in the same form module.

4 The "object" is the current form, Me.
The "procname" is my public subroutine that is named in my variable.
The "calltype" is VbMethod

Here is my test that worked:

Private Sub cmdTest_Click()
Dim strSubNm As String
strSubNm = "Test"
CallByName Me, strSubNm, VbMethod
End Sub

Public Sub Test()
MsgBox "It worked!"
End Sub
Feb 22 '10 #4
yarbrough40
320 100+
very cool! got it!
Feb 22 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
15
by: Miguel Orrego | last post by:
Hi, I have a variable in an app called GenericTitle which contains text, a persons job title funnily enough. I want to check whether this variable contains the word "director" and if it does,...
3
by: Jason | last post by:
I am having trouble using the CONTAINS function in sql server(enterprise manager). I am typing the following: Select * FROM mytable WHERE CONTAINS(myfield,'mystring') This returns the...
3
by: B-Dog | last post by:
I'm capturing the checked radio button to XML file using the name of the radio button. I want to read my xml file to find which button was checked on close and the check the appropriate button...
9
by: Joel Finkel | last post by:
Is there a way to execute a method if all we know is its name as a string? Let's say we have the following class. What is the code for the Execute method? I need a solution that works with the...
5
by: gabba | last post by:
Hi, is it possible to call a subroutine (or a function) using variable name? Sub a() Response.write("sub a") End sub Sub b() Response.write("sub b") End sub
2
by: 张韡武 | last post by:
We have preffered language set as variable in xslt: <xsl:variable name="preferred_language"> zh </xsl:variable> Data: <name xml:lang="de">Raw Materials (Mining incl.)</name> <name...
5
by: hairobinson | last post by:
How do we access the private member variable outside the class with out using friend ?
10
by: nas | last post by:
Hi Is there any way that i can find wether float variable contains fraction?? for eg:- if( isWholeNumber(b)) { //do here }
1
by: ragonz | last post by:
Hi, i'm kind of newbie in java programming. Now, i'm working on my task, n i hav a problem in using variable from other method. Here goes the code.. import java.awt.*; import java.awt.event.*;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.