I'm playing around with win32com.client for python to try to write/insert a row to a MS Access table. I've found an example of how to connect and query an Access table here. Basically, their code slightly modified for my own use is:
import win32com.client
connection = win32com.client.Dispatch(r'ADODB.Connection')
DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=c:\\testdb.mdb;'
connection.Open(DSN)
recordset = win32com.client.Dispatch(r'ADODB.Recordset')
recordset.Open('SELECT * FROM Table1', connection, 1, 3)
fields_dict = {}
for x in range(recordset.Fields.Count):
fields_dict[x] = recordset.Fields.Item(x).Name
print fields_dict[x], recordset.Fields.Item(x).Value
So this tells me how to execute a select statement on the Access table. I'd like to be able to write rows and data to the table. When using win32com for MS Office products, I tend to dive into the MSDN pages and try to interpret the VBA code for python code, but this one has me a bit handcuffed. Couple that with no examples found on the internet after lengthy searches has made me second guess whether or not this is possible? hopefully someone out there has played with this before and has a suggestion.
SELECTstatement with win32com then you can execute anINSERTstatement too, although specifying the parameters for anADODB.Commandobject will be somewhat verbose. A more common approach is to use pyodbc (or perhaps pypyodbc) with the Access ODBC driver to do such straightforward CRUD operations, and save win32com for performing lower-level manipulations of the database using Access DAO, e.g., to make structural changes that Access DDL cannot handle.DoCmd.*, or other application layers then use COM interface. Remember too VBA is an external component to Access.exe and COM-connects like you are with Python!