0

I'm trying to execute a function in vba inside a ms access db with python.

I tried this:

strDbName = "PathToMyDb"
ac = win32com.client.Dispatch ( "Access.Application" )
ac.OpenCurrentDatabase ( strDbName,False)
ac.Run("Performance_Attr_ModuloXX")
ac.Application.CloseCurrentDatabase ( )
ac.Application.Quit ( )

But I keep getting this error:

Traceback (most recent call last):
  File "C:\Users\PIN\PycharmProjects\test_db\main.py", line 32, in <module>
    ac.Run("Performance_Attr_ModuloXX")
  File "<COMObject Access.Application>", line 14, in Run
  File "C:\Users\PIN\PycharmProjects\test_db\venv\lib\site-packages\win32com\client\dynamic.py", line 369, in _ApplyTypes_
    *(dispid, LCID, wFlags, retType, argTypes) + args
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352562), None)

I already tried to check the function in vba and it works.

6
  • No, it does it with every function or subroutine I try Commented Feb 24, 2023 at 17:56
  • Does this answer your question? How to run a MS Access macro from python Commented Feb 24, 2023 at 19:14
  • Nope, I need to run a function not a Macro, I found how to print the reason of the issue with: print ( win32api.FormatMessage ( -2147352562 ) ) And it prints out the following: Invalid number of parameters. I don't understand since my function doesn't require any parameter, I also tried to set 1 parameter but it gives the same error code Commented Feb 24, 2023 at 19:16
  • It shows example code for both VBA and macro. It also shows code to Import library, which you don't show. Commented Feb 24, 2023 at 20:57
  • If the problem was the import or else the printed error would have been different, beside I already specified the problem is not vba. Commented Feb 24, 2023 at 21:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.