문제

I am trying to update an MDB using a VBS script. On one machine it works OK (WinXP and Office 2003) but on the other (Win7 64 bits VM with Office 2010) I get the error "ActiveX Component can't create object: 'DAO.DBEngine.36'". The code:

Dim dbe
Set dbe = CreateObject("DAO.DBEngine.36")

I tried with DAO.DBEngine, DAO.DBEngine.120 and .140 with no difference.
I don't understand where is the problem. Any clue ?


Update: I found I could make it work by callink the script like this:

c:\windows\syswow64\wscript MyScript.vbs Myargument

Apparently to call the 32 bits Wscript you must call it from syswow64, while the Wscript in system32 is the 64 bits version. A bit strange...

도움이 되었습니까?

해결책 2

You may need to run the script with the 32-bit version of the script interpreter:

%SystemRoot%\SysWOW64\wscript.exe C:\path\to\script.vbs

Taken from this answer to a similar question.

다른 팁

In 64 bits OS .vbs start as 64 bit process, so you need to restart (at the beginning) your script as 32 bit process.

'call it here
Force32bit

Dim dbe
Set dbe = CreateObject("DAO.DBEngine.36")

'just for testing:
WScript.Echo TypeName(dbe) 'DBEngine

'the rest of the code here...
Set dbe = Nothing

Sub Force32bit()
    Dim sWinDir, sSys64, sSys32, oShell
    Set oShell = CreateObject("WScript.Shell")
    sWinDir = oShell.ExpandEnvironmentStrings("%WinDir%")
    With CreateObject("Scripting.FileSystemObject")
        sSys64 = .BuildPath(sWinDir, "SysWOW64")
        If Not .FolderExists(sSys64) Then Exit Sub
        sSys32 = .BuildPath(sWinDir, "System32")
        If sSys32 = WScript.Path Then
            oShell.CurrentDirectory = sSys64
            oShell.Run "wscript.exe " & Chr(34) & _
            WScript.ScriptFullName & Chr(34), 1, False
            WScript.Quit
        End If
    End With
End Sub
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top