1

Hello I've been searching around and couldn't find anything up to date in this topic.

I would like to create a new .mdb file using pythons library pyodbc.

I've tried so many different ways and can never succeed. The main problem for me is to connect to a database that yet does not exist.

import pyodbc
DRV = '{Microsoft Access Driver (*.mdb, *.accdb)}'
PWD = ''
con=pyodbc.connect('DRIVER={};DBQ={};PWD={}'.format(DRV,'./'+new_path+'.mdb',PWD))

I've tried inserting a

f=open(new_path+'.mdb','a')
f.close()

in order to create a mdb file before trying to connect but could not succeed as well, it says that the file is corrupted.

3
  • Use the msaccessdb module. Commented Jun 7, 2020 at 14:01
  • Well I'm getting blocked to install other libraries, but I'll try it, thanks Commented Jun 7, 2020 at 14:03
  • 1
    If it's a permissions issue then try pip install --user msaccessdb Commented Jun 7, 2020 at 14:21

1 Answer 1

2

You can use the msaccessdb module for that. After you

pip install msaccessdb

or

pip install --user msaccessdb

you can simply do

import msaccessdb
msaccessdb.create(r'C:\path\to\new.mdb')
Sign up to request clarification or add additional context in comments.

Comments

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.