Run Method not working as expected (1 Viewer)

KernelK

Registered User.
Local time
Today, 13:00
Joined
Oct 3, 2006
Messages
173
Hey everyone,
I am trying to run a procedure by using a string value containing it's name. From all of the help files, the Run method is the way to go. However, when testing with it, I cannot make it work. I have the following code on a form that I am testing the method with:

Code:
Option Compare Database
Option Explicit

Private Sub Command0_Click()
    Call TestMod("MessageMod")
End Sub


Sub TestMod(strMod As String)
    Application.Run strMod
End Sub


Sub MessageMod()
    MsgBox "TESTING"
End Sub

When I click the button on the form, I get the following error: "Run-time error '2517': VSD Ticket Tracking can't find the procedure 'MessageMod.'"

I have also tried appending the form name before the procedure with the same error returned:

Code:
Private Sub Command0_Click()
    Call TestMod("Form1.MessageMod")
End Sub

What am I doing wrong here? It does not make any sense to me at this point.
 

KernelK

Registered User.
Local time
Today, 13:00
Joined
Oct 3, 2006
Messages
173
I wish...

Good thought, but it returns the same error when I place MessageMod into my Globals module.
 

KeithG

AWF VIP
Local time
Today, 10:00
Joined
Mar 23, 2006
Messages
2,592
Do you have set as a Public procedure?
 

RoyVidar

Registered User.
Local time
Today, 19:00
Joined
Sep 25, 2000
Messages
805
What version are you on?

If you're back on 97, I think you're out of luck. It works on my setups a2k and later.
 

KernelK

Registered User.
Local time
Today, 13:00
Joined
Oct 3, 2006
Messages
173
After checking out Roy's link, I tried to reconfigure to use the Eval method (although this is not preferred as I am forced to use a function).

Code in Form:
Code:
Private Sub Command0_Click()
    Call TestMod("MessageMod")
End Sub

Sub TestMod(strMod As String)
    Dim strEval As String
    strEval = Eval(strMod)
End Sub

Code in Module:
Code:
Public Function MessageMod() As String
    MsgBox "TESTING"
    MessageMod = "Test"
End Function

"Run-time error '2482': VSD Ticket Tracking can't find the name 'MessageMod' you entered in the expression.

I also tried putting the Public keyword in front of MessageMod as a Procedure in my module, with the same results.
 

KernelK

Registered User.
Local time
Today, 13:00
Joined
Oct 3, 2006
Messages
173
Access 2003. Frustrating huh? It doesn't make any sense as I think I am using it correctly...at least from all of the examples I have seen I am.....
 

KeithG

AWF VIP
Local time
Today, 10:00
Joined
Mar 23, 2006
Messages
2,592
why not just use Call MessageMod
 

KernelK

Registered User.
Local time
Today, 13:00
Joined
Oct 3, 2006
Messages
173
This is just a test to get the Run method to work properly.

I will really be using the Run method to run certain procedures that are pulled from a table query as string values. This is the only Method I have found for accomplishing that. I wish I could just do Call strMod, but unfortunately that doesn't fly either ;-)
 

KernelK

Registered User.
Local time
Today, 13:00
Joined
Oct 3, 2006
Messages
173
I cannot get CallByName to work either as that only invokes methods of objects, for which my procedure is not.
 

KernelK

Registered User.
Local time
Today, 13:00
Joined
Oct 3, 2006
Messages
173
Simply.....amazing......

It works just fine when I put MessageMod into a brand new module all by it's lonesome....but it doesn't like being in the module I already have for my Global functions......what the heck......
 

RoyVidar

Registered User.
Local time
Today, 19:00
Joined
Sep 25, 2000
Messages
805
Edit: Seing it is "solved", changing a bit.

Your base seems to suffer from some corruption. One recommandation would be to use the /decompile option - see Tony Toews page http://www.granite.ab.ca/access/decompile.htm for detailed instructions - note - between step 2 and 3, exit the base, and reopen it in a new instance of Access (without running any code - shift), to completely clean out the corrupted parts.
 

KernelK

Registered User.
Local time
Today, 13:00
Joined
Oct 3, 2006
Messages
173
Yeah....I have run into corruption before that has caused similar strange happenings with Access, I just didn't suspect it this time because I have never used the Run Method before and thought I was perhaps just using it wrong....

Thanks for all of the help guys!
 

Users who are viewing this thread

Top Bottom