import pyodbc

db_path = r'c:\fuentes\proyectos delphi\RAUL_ASENCIO\GESTION\documentacion raul asencio\datos\contabilidad\0042026.accdb'
conn_str = f'DRIVER={{Microsoft Access Driver (*.mdb, *.accdb)}};DBQ={db_path};'
conn = pyodbc.connect(conn_str)
cursor = conn.cursor()

tables = [row.table_name for row in cursor.tables(tableType='TABLE')]
for t in tables:
    try:
        cursor.execute(f"SELECT TOP 1 * FROM {t}")
        col_names = [d[0] for d in cursor.description]
        cif_cols = [c for c in col_names if 'CIF' in c or 'NIF' in c]
        if cif_cols:
            cursor.execute(f"SELECT COUNT(*) FROM {t}")
            cnt = cursor.fetchone()[0]
            print(f"Table {t}: count={cnt}, cols={cif_cols}")
    except Exception as e:
        pass
