How to pass combobox's value to a variable on a query python addin toolbar

03-20-2020 09:54 AM
New Contributor

Hi All,

Trying to capture a variable from a combobox and use it on SQL query, but it doesn´t work.

Any idea how to create the variable "query"?

import arcpy
import pythonaddins
arcpy.env.workspace = r'C:/Users//Documents/Work/Access Resource/Propiedad Minera/Tools/PMdata.mdb'
arcpy.env.overwriteOutput = True
arcpy.env.addOutputsToMap = True
query = [County] = fc

class ButtonClass2(object):
"""Implementation for Test3_addin.button_1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):

class ButtonClass3(object):
"""Implementation for Test3_addin.button_2 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):

class ComboBoxClass1(object):
"""Implementation for Test3_addin.combobox (ComboBox)"""
def __init__(self):
self.items = ["Orange",Hiils ""]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
def onSelChange(self, selection):
print"New Selection:",selection
fc =selection
def onEditChange(self, text):
def onFocus(self, focused):
if focused:
self.mxd = arcpy.mapping.MapDocument('current')
layers = arcpy.mapping.ListLayers(self.mxd)
self.items = []
for layer in layers:
def onEnter(self):
def refresh(self):

0 Kudos
1 Reply
Esri Regular Contributor

Hi Sergio Pizarro‌, 

The 3rd argument to the arcpy.MakeFeatureLayer_management() method is a where clause in SQL syntax. In your sample code you have:


query = [County] = fc


This line of code is not a valid SQL syntax, nor is it valid Python syntax.


In this case, the query variable must be a string, so you should put single quotes around the clause.


Here is a doc which goes into SQL syntax for where clauses in more detail:


Go ahead and try that. In the meantime I'm going to move your post to the Python community space for you to hopefully get more help on this if needed:

0 Kudos