-1

I'm trying to establish connection with Microsoft Office and to run a query but it is showing error

Here is my code:

import pyodbc

conn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:\Python\Database\att2000.accdb;')
cursor = conn.cursor()
cursor.execute("SELECT CHECKINOUT FROM att2000 Where CHECKTYPE = O")

for row in cursor.fetchall():
    print (row)

Here is the error:

Error is occurring while executing the query
----> 5 cursor.execute("SELECT CHECKINOUT FROM att2000 Where CHECKTYPE = O")
      6 
      7 for row in cursor.fetchall():

ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC Microsoft Access Driver] The Microsoft Access database engine cannot find the input table or query 'att2000'. Make sure it exists and that its name is spelled correctly. (-1305) (SQLExecDirectW)")
1
  • 1
    att2000 is the name of the database file. Apparently it does not contain a table or view that is also named att2000. Open the database in the Microsoft Access UI and verify what the table/view names are. Commented Dec 11, 2020 at 12:27

1 Answer 1

0

I guess you mix up the file name and the table name.

Try:

cursor.execute("Select * From CHECKINOUT Where CHECKTYPE = O")
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.