Running VBA code through Macro

navi95

Registered User.
Local time
Today, 07:13
Joined
Jan 3, 2013
Messages
59
Hello again guys!

So im trying to execute a VBA code on my AutoExec macro.
This is what ive done so far:

1.) Created a module with the following code:
Option Compare Database
Option Explicit

Public Function import() As Boolean
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Kunden", "e:\pizza program\kunden.xlsx", True
End Function

2.) Inserted "RunCode" into my macro and using "import()" as the name of the function

But it doesnt seem to want to work, when I load up the database the macro it comes up with an error message basically saying that the code has an expression which cannot be found.

Any thoughts?
 
I think Import is probably not a good name to use for a function, as it is a reserved word.

Try calling it OpenImport or something similar.
 
I think Import is probably not a good name to use for a function, as it is a reserved word.

Try calling it OpenImport or something similar.

Yes! That has fixed it...thank you so much! I would never had thought of that:D
 
Yep, using reserved words in a non-standard way always give you grief SOMEWHERE. And all of the really good simple words like Open and Close and stuff like that are already in use.

Just a thought in passing because you didn't mention it. If this is something you would want to run on a scheduler, be absolutely scrupulously sure that the Macro doesn't finish without quitting the application. Otherwise you end up with "dangling" copies of MSACCESS in memory until you fill your virtual memory file. Which you will, and fairly quickly at that.
 

Users who are viewing this thread

Back
Top Bottom