Application.Run method not working as intended, Run-time error 2517

Stormin

Nawly Ragistarad Usar
Local time
Today, 06:45
Joined
Dec 30, 2016
Messages
76
Hi all,

I am trying to call a procedure with paramters from within another procedure in Access 2010. I've used this method before but for some reason it's throwing a strange error this time.

For testing I have created a new normal module, Module 1, and put in the following code:
Code:
Option Explicit


Function test_message_test(Optional str_test_Text As String)
    Debug.Print str_test_Text & " <-- that was some text"
End Function


Function test_callfunction_test()
    Application.Run test_message_test("Hello world.")
End Function


Function test_callfunctionwithoutparams_test()
    Application.Run test_message_test
End Function
When I run either test function--and even when I completely remove the parameters from the message function--I get an error thrown after Application.Run has executed.

Code:
Microsoft Visual Basic
Run-time error '2517':

MyDatabaseName cannot find the procedure '.'
I have no idea why this is thrown since I've used Application.Run before with no issues.
The only way to avoid the error message is to change the code to:
Code:
Function test_callfunction_test()
    On Error GoTo err_hnd
    Application.Run test_message_test("Hello world.")
    Exit Function
err_hnd:
    If Err.Number = 2517 Then Resume Next
End Function
However I don't like just ignoring an error when I don't know what is causing it.

Does anybody know? Do you get the same error when you try the above code?

Edit: Added note, I tried this in a new empty database with no other applications open and it still threw the error.
Edit2: Should mention that the error is triggered after the "End Function" line is run in test_message_test()
 
Last edited:
Okay so it turns out it was me not using Application.Run properly.
Firstly since in other places I was using a variable as the function name, I didn't enclose it in quotes for this test, which didn't help at all.
But the main reason this failed to work was the incorrect syntax I was using. I was trying to call the function with it's full name and parameters (first time doing so) but instead you call the function name, and then set the paramters in the .Run function.

The following code is corrected and working:
Code:
Option Explicit

Function test_message_test(Optional str_test_Text As String)
    Debug.Print str_test_Text & " <-- that was some text"
End Function

Function test_callfunction_test()
Dim s As String
s = "test_message_test"
    Application.Run s, "Hello World."
End Function

This webpage contains some useful info and helped me realise my mistake:
https://groups.google.com/forum/#!topic/comp.databases.ms-access/p4QCkbA8XpM
 
P.S. This concludes my week of asking stupid questions :banghead:
 

Users who are viewing this thread

Back
Top Bottom