0

I have a database with huge tables. Loading and processing them via pyodbc is taking ages, so no option.

Currently I am manually exporting my updated tables from MS Access into a .csv and then loading them into python.

Now I want to automate this process via python. I have seen a similar problem here

My code:

    import os
    import win32com.client

    current_PATH = os.getcwd()
    db_PATH = current_PATH+"\\database.accdb;"

    oApp = win32com.client.Dispatch("Access.Application")
    oApp.OpenCurrentDatabase(db_PATH)

    acExportDelim = 2
    oApp.DoCmd.TransferText(acExportDelim, None, "table_to_export", 'Output.csv', True)

    oApp.DoCmd.CloseDatabase
    oApp.Quit
    oApp = None

But all I get in response is:

    Traceback (most recent call last):
    File "C:\Users\...\export_script.py", line 9, in <module>
    oApp.OpenCurrentDatabase(db_PATH)
    File "<COMObject Access.Application>", line 3, in OpenCurrentDatabase
    File "C:\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 282, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
    [Finished in 6.9s with exit code 1]

What is the correct way to export a table to a .csv?

Edit: That is how my test table looks like: test_table

12
  • 1
    Please post entire traceback as an error message is outputted usually at the end. Also, remove the semicolon in db_path. Commented Mar 29, 2016 at 12:53
  • This is the entire traceback I get. I did remove the semicolon, but i still get the same Traceback. Commented Mar 29, 2016 at 15:26
  • Did you remove the semicolon? This might be due to your IDE or Anaconda install with win32com. Can you run it a command line (PowerShell or Cmd prompt): python c:\path\to\script.py. Commented Mar 29, 2016 at 18:01
  • I did remove the semicolon. When I run it via CMD I get an additional information: It says: pywintypes.com_error (-2147352567,'Ausnahmefehler aufgetreten.', (0, None, 'Das Feldtrennzeichen für die angegebene Textdatei entspricht dem Dezimaltrennzeichen oder Texttrennzeichen.','jeterr40.chm', 5003411, 2146824847), None) It is german and tells me that the delimiter is the same as the decimal separator. But I did not set a custom delimiter so it should take the system default one. Commented Mar 29, 2016 at 19:27
  • Can you include first few rows of data for reproducible example? Also, try manually exporting from you tables using ribbon on Access (External Data tab / Text file export - arrow out). Does error re-occur? Commented Mar 29, 2016 at 19:49

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.