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.
Frage
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...
Lösung 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.
Andere Tipps
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