[python-win32] running an Access VBA procedure fails

mchl gdbt mchlgdbt at hotmail.com
Sun Oct 22 08:03:39 CEST 2006


Hi,

I have a VBA sub routine in an access file that I need to run from python.

let's say

Public Sub test(arg1 As String)

    MsgBox ("test succeeded" + arg1)

End Sub

ok from excel I do this
Sub MyTest()

    strDbName = "C:\db1.mdb"
    Dim ObjAccess As Object
    Set ObjAccess = GetObject(strDbName, "Access.Application") ' if I 
opencurrentdatabase, fails if database is already open

    Result = ObjAccess.Run("test", "Argument") ' need Result= because it 
doesn't compile otherwise, (oddly a test function that doesn't need an 
argument also doesn't need a result)
End Sub

That works fine. (Also works fine if I use an access.application explicitly)
In python, I do the following:
import win32com.client
AccessAppDB = win32com.client.GetObject("C:\db1.mdb")
AccessAppDB.Run("test","Argument")
fails with
---------------------------------------------------------------------------
pywintypes.com_error                                 Traceback (most recent 
call
last)

C:\Documents and Settings\HP_Administrator\<ipython console>

C:\Documents and Settings\HP_Administrator\<COMObject access.application> in 
Run
(self, Procedure, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, 
Arg10, A
rg11, Arg12, Arg13, Arg14, Arg15, Arg16, Arg17, Arg18, Arg19, Arg20, Arg21, 
Arg2
2, Arg23, Arg24, Arg25, Arg26, Arg27, Arg28, Arg29, Arg30)

C:\Python24\lib\site-packages\win32com\client\dynamic.py in 
_ApplyTypes_(self, d
ispid, wFlags, retType, argTypes, user, resultCLSID, *args)
    249
    250         def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, 
user,
resultCLSID, *args):
--> 251                 result = self._oleobj_.InvokeTypes(*(dispid, LCID, 
wFlag
s, retType, argTypes) + args)
    252                 return self._get_good_object_(result, user, 
resultCLSID)

    253

com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, 
-214735
2562), None)

The same error happens if I use Access to OpenCurrentDatabase (ie. 
Dispatch("access.application"), opencurrentdatabase( ), then run)

What am I doing wrong?

thanks,
Michaël

_________________________________________________________________
Say hello to the next generation of Search. Live Search – try it now. 
http://www.live.com/?mkt=en-ca



More information about the Python-win32 mailing list