Access Application.Run "Can't Find The Procedure" only on another workstation

745 views Asked by At

Coming in off my last question ("Unspecified Error" 80004005 when creating new Access database, only on another workstation)...

Again, I have Office 2013 installed, my coworker has Access 2007. My script below creates a new Access database through automation, imports a series of VBA modules from text, then runs a sub found in one of the imported modules. The script runs fine on my machine, but on my coworker's machine it says Microsoft Office Access can't find the procedure 'ImportAllSource.' We've also tried prefixing the name of the procedure with the name of the module it lives in ("VCS_ImportExport.ImportAllSource"), and the name of the project as it appears in the VBE environment ("ImportTest.ImportAllSource"), but with no luck and the same error.

Revised script:

'use strict';

/**
 * AcNewDatabaseFormat Enumeration
 * Used with the NewCurrentDatabase method to specify the database format of the newly created database.
 */
var acModule = 5,
    dbText = 10,
    acNewDatabaseFormat = {
        UserDefault: 0,
        Access2000: 9,
        Access2002: 10,
        Access12: 12
    };

var fs = new ActiveXObject('Scripting.FileSystemObject');
var access = new ActiveXObject('Access.Application');
var basePath = fs.GetParentFolderName(WScript.ScriptFullName);
var db, prop, vcsFolder, fCur, module;

//Create DB and set up some superficial things.
access.NewCurrentDatabase(basePath + '\\ImportTest.accdb', acNewDatabaseFormat.Access12);
db = access.CurrentDb();
prop = db.CreateProperty('AppTitle', dbText, 'IG IMI Database');
db.Properties.Append(prop);
prop = db.CreateProperty('StartUpForm', dbText, 'Main Switchboard');
db.Properties.Append(prop);
db.Properties('UseMDIMode') = 1;

//Add MSAccess-VCS modules
vcsFolder = fs.GetFolder(basePath + '\\MSAccess-VCS');
fCur = new Enumerator(vcsFolder.files);
for (; !fCur.atEnd(); fCur.moveNext()) {
    module = fCur.item().Name.replace('.bas', '');
    access.LoadFromText(acModule, module, fCur.item());
}

access.Run('ImportAllSource');
access.Quit();
1

There are 1 answers

0
p0lar_bear On BEST ANSWER

Had an epiphany. The problem was some code in the loaded modules - namely, a couple Declare statements using the PtrSafe keyword. It's valid syntax in Access 2013, but not in 2007.

So, if there's an error with the VBA code in a loaded module, Access will play dumb when you try to invoke Application.Run.