Python to open ADODB recordset and add new record
<p>in my wxPython app which I am developing I have written a method which will add a new record into an access database (.accdb). I have procured this code from online search however am not able to make it work.  Below is the code:-</p>

<pre><code>def Allocate_sub(self, event):
    pth = os.getcwd()
    myDb = pth + '\\myAccessDB.accdb'
    DRV = '{Microsoft Access Driver (*.mdb)}'
    PWD = 'pw'
    # connect to db
    con = win32com.client.Dispatch(r'ADODB.Connection')
    con.Open('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s' % (myDb))
    cDataset = win32com.client.Dispatch(r'ADODB.Recordset')
    #cDataset.Open("Allocated_Subs", con, 3, 3, 1)
    cDataset.Open("Allocated_Subs", con, 3, 3, 1)
    cDataset.AddNew()
    cDataset.Fields.Item("Subject").Value = "abc"
    cDataset.Fields.Item("UniqueKey").Value = "xyzabc"
    cDataset.Update()
    cDataset.close()
    con.close()
</code></pre>

<p>However whenever I trigger this code by clicking the button to which I have Bind it I get error saying:-</p>

<p>Can anyone please help me resolve this or let me know of a different way to open a recordset using ADODB and then add a new record into it.</p>

<p>Many thanks.</p>

<p>Regards,
Premanshu</p>

<p>I figured the solution, posting here just in case someone refers to it...
it's a small correction in line</p>

<pre><code>cDataset.Open("Allocated_Subs", con, 3, 3, 1)
</code></pre>

<p>it should be:-</p>

<pre><code>cDataset.Open("Allocated_Subs", con, 1, 3)
</code></pre>

<p>Regards,
Premanshu</p>

python adodb recordset