Home > Net >  Run MS access Function from python
Run MS access Function from python

Time:02-22

Trying to run MS access function from python. Note that I have Access macro object with RunCode action that calls the function in the module 2. This macro is nameed as del_all_records() , function has the same name too del_all_records()

This is my python code:

# search for directory
directory = r'C:/Users/'   username   /Documents/Customer/02.weekly Report/'

ac = win32com.client.Dispatch("Access.Application")
ac.Visible=True
ac.OpenCurrentDatabase(directory  '/amazon.accdb')
ac.DoCmd.RunMacro('del_all_records()')
ac = None

This trace back error:

Traceback (most recent call last):
  File "directory = r'C:/Users/'   username   /Documents/Customer/02.weekly Report/db_load.py", line 15, in <module>
    ac.DoCmd.RunMacro('del_all_records()')
  File "<COMObject <unknown>>", line 2, in RunMacro
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, 'You canceled the previous operation.', 'vbaac10.chm', 5738, -2146826287), None)

CodePudding user response:

As you have the application open, you should be able to call the function directly:

ac.del_all_records()

CodePudding user response:

Code did not work until I did not change the path.

I have change in the path this

/

With this:

\\
  • Related