Run a Function

2wistd

Registered User.
Local time
Today, 13:09
Joined
Jan 17, 2013
Messages
66
I am getting kind of lost. I try to run a function off of a button click.

The code is

Private Sub Command_Click()
Run fuctionname()
End Sub

The code is ran, but then I get a msg box:
Run-time error '2517':

Microsoft Office Access can't find the procedure '.'


What am I missing?
 
It would just be

fuctionname

don't include the word "Run".
 
Functions return a value -
if the function returns a string then
Dim MyString as String
MyString = functionname()

Or -
Functionname ' no parens
then you are running it like a subroutine

The Message Box Function can be run as an example

Msgbox "Hello World"

Answer = Msgbox("hello world", vbYesNo, "Returns a value")
 
Last edited:
is your function within a module? This type of error is usually caused by trying to run a sub which is in a private environment such as code tied to a form or report.
What happens if you move the function into a module, does it still error

David
 
pbaldy is correct - Run isn't what to use, (although application.run is possible, but doesn't make much sense unless you're automating access from another database or another office app) - just use the name itself.

However, generally you use a function to pass a parameter to it and get back a return value. In fact, in Access vba I think a function has to return something - (if it doesn't the point stands regardless; that's normal usage).

If you just want to write a sub that does something (and it can also take arguments passed to it, or not), then use a Sub, not a Function. And call it by typing its name, nothing else.
 

Users who are viewing this thread

Back
Top Bottom