'Tkinter to Connect to MS Access Database

I'm trying to make a GUI using tkinter to select the MS Access Database. I get an error: "General error Unable to open registry key Temporary (volatile) Ace DSN for process 0xcb8 Thread 0x39b8 DBC 0x1d234678" pointing to the connection line. Why doesn't this work.

import pandas as pd
import pyodbc
import numpy as np
from tkinter import *
from tkinter import ttk, filedialog
from tkinter.filedialog import askopenfile
import os
 
# Create an instance of tkinter frame
win = Tk()

# Set the geometry of tkinter frame
win.geometry("700x350")

def open_file():
   file = filedialog.askopenfile(mode='r', filetypes=[('MS Access File', '*.accdb')])
   if file:
      filepath = os.path.abspath(file.name)
      Label(win, text="The File is located at : " + str(filepath), font=('Aerial 11')).pack()
      conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ = ' + filepath)
      qry=("select * from Table1")
      dataf = pd.read_sql(qry, conn)
      conn.close()      

# Add a Label widget
label = Label(win, text="Browse for file", font=('Georgia 13'))
label.pack(pady=10)

# Create a Button
ttk.Button(win, text="Browse", command=open_file).pack(pady=20)

win.mainloop() 
 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source