简体   繁体   中英

Python comtypes with MS Access

I have the following Python 2.7 code that works perfectly on a Windows 7 machine:

from comtypes.client import CreateObject
app = CreateObject('Access.Application')
from comtypes.gen import Access
DBEngine = app.DBEngine

On two others (Windows 7 and Windows 10) with MS Access 365 installed (latest version), I get the following error:

_ctypes.COMError: (-2147312566, 'Erreur lors du chargement de la biblioth\xe8que/DLL du type.', (None, None, None, 0, None))

(Meaning "Error loading DLL library)

I assume it's a DLL issue. Reinstalling Office didn't solve it. Has anyone already met that issue? Otherwise, what would be the general method to find the problem/fix it?

Why not using win32com.client for that? comtypes is not so stable and is useful for custom COM interfaces (where other approach is impossible). All MS Office products have nice and standard IDispatch COM interface that are reachable by win32com.client . Standard PyWin32 docs describe "Excel.Application" example, but it can be easily applied for MS Access as well.

Fortunately there are several examples on StackOverflow:

Python code for running ms-Access Module Subroutine

Python Create Access database using win32com

I found the answer to that question: the "click-to-run" version of Office 365 runs in a virtual environment and the Python libraries may not find it.

The answer to that issue is to uninstall Office and reinstall it as a normal download. After we did that, the program (which had already been tested successfully on another machine) started working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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