function call using runcode

M

mark_jm

I am trying to call a function written in VBA using the runcode command
within the macro window.

How do I declare the function and then call it succesfully.

I am trying to do this because I have some append queries running as a click
event on a button. Ordinarilly I would just write the code and put that on
the click event, but I cant becasue the append query via the macro is there ?
I am trying to carry ouit a few checks on a form before I let the append
query run, so I am a bit stuck

Regards

Mark
 
K

Klatuu

The procedure named in a RunCode action must be a Function. It will not run
a Sub. It also must be in a Standard module.

But, I don't understand why you need the macro. If you are running other
code to verify information on the form in the click event of a command
button, there is no reason you can't run the append query based on whether
the information is valid. When running any Action query (Append, Update,
Delte, Make Table), I prefer using the Currentdb.Execute method. It is
faster and does not cause the SetWarnings message to pop up. You can use
either a stored query or SQL you construct programmatically. If you are
using a stored query, it would look like this:

Currentdb.Execute("MyQueryName"), dbFailOnError

The dbFailOnError is necessary because if the query fails and you don't have
this option specified, you will never see the error.
 
Top