RunCode not finding VBA code

jamphan

Registered User.
Local time
Today, 10:15
Joined
Dec 28, 2004
Messages
143
I am trying to incorportate this code
CurrentDb.Execute "DELETE FROM CAFILE" into a macro. What I want the macro to do is delete the contents of the file named CAFILE and then import a text file I have on a shared network drive to replace the contents of CAFILE. I am not able to get the macro to find the code I have written. I am using the RunCode action in the macro. Can someone help me with this? Thanks!
 
The code you run needs to be put into a function.
 
I guess that is what I am trying to do, put the code in a function. I have it in a Sub in the code part of my form. Is this what you were referring to when you say Function? I am not really sure how to get my macro to run this first then run the next part of the macro to import the text file. Can you help with this?
 
It can't go in a sub because a sub is a subroutine. It can't go in a form because a form's module is a Class module and all its contents are closed off from other modules.

Copy the sub to a standalone module, New on the Modules Tab, and paste it there. Then change Sub to Function.
 
That was what I needed. Thanks! It works perfectly now.
 

Users who are viewing this thread

Back
Top Bottom