问题
What I have is a JScript file that gets called by cscript
, and this script is a proof-of-concept that creates a new Access 2007 format database, imports a set of VBA modules into the database, and then runs a subroutine from the imported modules.
This script works flawlessly on my own computer. I have Office 2013 installed. However, I brought this script over to a coworker's machine and had him attempt running it. On his machine, we get an error that looked something like, createdb.js (22, 1): Unspecified error
and the error code is 80004005. My code, below:
'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, null, "", "");
//access.OpenCurrentDatabase(basePath + '\\ImportTest.accdb');
db = access.CurrentDb();
prop = db.CreateProperty('AppTitle', dbText, 'My New Database');
db.Properties.Append(prop);
prop = db.CreateProperty('StartUpForm', dbText, 'Main Form');
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();
Line 22, character 1 is access.NewCurrentDatabase(basePath + '\\ImportTest.accdb', acNewDatabaseFormat.Access12, null, "", "");
. Office (and Access!) 2007 is installed on his machine. We tried other AcNewDatabaseFormat
s with no luck. What could possibly be the issue here?
回答1:
Since you're not using any of the optional parameters, just leave them off:
access.NewCurrentDatabase(basePath + '\\ImportTest.accdb', acNewDatabaseFormat.Access12);
You only need to specify a value for optional parameters if there are other parameters you want to use later in the argument list.
来源:https://stackoverflow.com/questions/30821983/unspecified-error-80004005-when-creating-new-access-database-only-on-another