简体   繁体   English

通过VBScript使用ADOX

[英]Using ADOX via VBScript

Shouldn't you be able to implement the ADOX library via VBScript? 您不应该能够通过VBScript实现ADOX库吗? The code below runs perfect via Access 2010 on Windows 7, Office 2010 32-bit, but doesn't via a VBScript. 下面的代码可以通过Windows 7,Office 2010 32位上的Access 2010完美运行,但不能通过VBScript运行。 Isn't ADOX just another COM Object like say FileSystemObject? ADOX不只是另一个COM对象,例如FileSystemObject吗?

Dim objADOX

Set objADOX = CreateObject("ADOX.Catalog")
objADOX.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Zamdrist\Desktop\Work\Scripts\Shell.accdb"
MsgBox objADOX.Tables.Count

Sorry, I should point out, VBScript complains that the provider does not exist. 抱歉,我应该指出,VBScript抱怨该提供程序不存在。 Odd because I do in fact have Access 2010 installed. 奇怪的是,实际上我确实安装了Access 2010。

This is not meant as an answer just simply as a tip that has helped me tremendously. 这不只是为了给我一个极大的帮助而已,而是一个答案。 I am constantly working with providers that only work with 32 bit so i always add the attached code to all of my scripts. 我一直与只能使用32位的提供程序进行合作,因此我总是将随附的代码添加到所有脚本中。 This way it doesn't matter if the machine that is executing the code is 32 or 64 bit. 这样,执行代码的机器是32位还是64位都没有关系。

'Check for 64 bit and run as 32 bit if needed.
'On error resume next

Set oFso = CreateObject("Scripting.FileSystemObject")
Set oWs = CreateObject("WScript.Shell")

windowsdir = oWs.ExpandEnvironmentStrings("%windir%")

If InStr(LCase(WScript.FullName), windowsdir & "\system32\") And oFso.FolderExists(windowsdir & "\SysWow64") Then       
    oWs.Run windowsdir & "\SysWow64\WScript.exe """ & WScript.ScriptFullName & """"
    WScript.Quit
End If

'code to run as 32 bit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM