Python Forum
Using VBA to Call a Python script causes error in pyodbc connector
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using VBA to Call a Python script causes error in pyodbc connector
#1
Hello, I am using vba to call a python script that gets information from a Jira API and uses pyodbc to update an Access database. Everything works fine if I open the python script and run it from an interpreter, but if i use vba to call the script I get the below error.

Error:
Traceback (most recent call last): File "C:\Users\PCarra\Desktop\CktOpsDb\Scripts\updateDb.py", line 7, in <module> conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=\\**Omitted on purpose**\Backend\Inventory_be.accdb;')pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Python code below:

from collections import Counter
from jira import JIRA
from pprint import pprint
import requests, json, urllib3, os, pyodbc, usaddress

#Connection string for database
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=\\**omitted on 
                      purpose**\Backend\Inventory_be.accdb;')
cursor = conn.cursor()
...
...
cursor.execute('''
                UPDATE CircuitInfoTable
                SET CircuitID = ?, Bandwidth = ?, Region = ?, HandoffALocAddress = ?, HandoffALocCity = ?, HandoffALocST = ?, 
                Carrier = ?, HandoffZLocAddress = ?, HandoffZLocCity = ?, HandoffZLocST = ?, SegmentID = ?, Legacy = ? WHERE 
                LatestJiraTicket = ? 
                ''', params)

conn.commit()
VBA call to script:

Output:
Dim x As Variant Dim strProgramName As String strProgramName = CurrentProject.Path & "\Scripts\updateDb.py" Shell Environ$("COMSPEC") & " /k" & strProgramName, vbNormalFocus
Any ideas on what may be causing the above error since it works through an interpreter but not after I call the script using VBA?

Thanks for the help!
Reply
#2
I found my problem from within the shell called from vba I needed to specify a 32 bit version of python to execute the script. Also I created a System DNS connector on my system. Not a python code problem. Sorry!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 719 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  Mysql and mysql.connector error lostintime 2 661 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Using pyodbc&pandas to load a Table data to df tester_V 3 796 Sep-09-2023, 08:55 PM
Last Post: tester_V
  How to pass encrypted pass to pyodbc script tester_V 0 849 Jul-27-2023, 12:40 AM
Last Post: tester_V
Sad "PriceSystem" Python Script error to Shopify API Alphetto 0 435 Jul-04-2023, 10:03 AM
Last Post: Alphetto
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,181 Jun-29-2023, 11:57 AM
Last Post: gologica
  pyodbc gmerritt 8 2,877 Feb-21-2022, 07:21 PM
Last Post: gmerritt
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,665 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,581 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  Call a bash script from within a Python programme Pedroski55 6 2,434 Dec-06-2021, 01:53 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020