I am trying to run a sub in Access VBA from Python but it looks like I am facing an issue I do not quite manage to understand. Below the code that correctly opens the database (Access) but fail to run the VBA code
import os, os.path
import win32com.client
ac = win32com.client.Dispatch("Access.Application")
ac.Visible=True
ac.OpenCurrentDatabase(os.path.abspath("C:\Database.accdb"))
ac.Application.Run("Database.accdb!module3.subpycall")
The sub I am calling is quite straight forward and it is calling a click event of a button. The code of the sub can be found below
Sub subpycall()
Call cmdUniverse_Click
End Sub
When running python,as per the above code, Access opens correctly, the main forms opens correctly but it returns the following error. Can anyhone help fixing this error?
File "C:\ON_CHAV.py", line 7, in ac.Application.Run("Database.accdb!module3.subpycall") File "<COMObject >", line 14, in Run File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\win32com\client\dynamic.py", line 287, in ApplyTypes result = self.oleobj.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "Database cannot find the procedure 'Database.accdb!module3.subpycall.'", None, -1, -2146825771), None)