<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use user input in Combo Box to perform a Definition Query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46211#M3711</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would suggest setting a queryVal variable to some default value ("") at the start of the toolbar script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next, in the onEditChange event handler for the combo box,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;declare the queryVal variable as global, and set queryVal to the combobox text.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def onEditChange(self, text):&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; global queryVal &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryVal = str(text)[\CODE]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now the queryVal vaiable is available for use in the onClick handler &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for an Apply button.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is where you would build the query string using queryVal as the value,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and pass it to the geoprocessing tool (and apply the definitionQuery).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Doing it this way also gives the user a moment to inspect what she has typed,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;before the (possibly nonsensical) value is applied as a query....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rereading your post, I see your concern is now with the query not working... oops.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe breaking out the value setting and value applying, as I suggest, would help make the issue clearer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Jun 2013 18:34:25 GMT</pubDate>
    <dc:creator>markdenil</dc:creator>
    <dc:date>2013-06-07T18:34:25Z</dc:date>
    <item>
      <title>Use user input in Combo Box to perform a Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46208#M3708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm nut sure which function (i'm assuming onEnter) to use and how to write the code to be able to get a users input ( type it in the text box of the combo box), hit enter and have it performe a definition query on a layer.&amp;nbsp; I can accomplish this by using a search cursor and populating the combo box with the returned values, but i prefer no to do this as returns a rather large list.&amp;nbsp; Any thoughts?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 18:07:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46208#M3708</guid>
      <dc:creator>danielchaboya</dc:creator>
      <dc:date>2013-06-06T18:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Use user input in Combo Box to perform a Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46209#M3709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have used onEditChange for capturing the type-in input&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and then used an OK button to start the processing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 11:54:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46209#M3709</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-06-07T11:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Use user input in Combo Box to perform a Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46210#M3710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have used onEditChange for capturing the type-in input&lt;BR /&gt;and then used an OK button to start the processing.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried this ....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def onEnter(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = mxd.activeDataFrame
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Lots = arcpy.mapping.ListLayers(mxd, "Lots", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; plan = SearchPlanNumber_1.value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = '\"PlanNumber\" = \'' + str(plan) + '\''
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print plan
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print query
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "LotSelection":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = '"PlanNumber" = \'' + plan + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I comment out the SelectByAttribute and df.zoomToSelectedFeatures, I can manipulate the definition query.&amp;nbsp; However,&amp;nbsp; It looks like there is something wrong with the where clause in the SelectByAttribute tool.&amp;nbsp; It fails with the following error ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Traceback (most recent call last):
&amp;nbsp; File "C:\Users\dchaboya\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{7657B98A-A37F-CA5E-A8E1-C6CEF093100B}\SearchPlanNumber_addin.py", line 32, in onEnter
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query)
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6435, in SelectLayerByAttribute
&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e
RuntimeError: Object: Error in executing tool&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Both print statements are returning the values that i'm expecting.&amp;nbsp;&amp;nbsp; For example,&amp;nbsp; if I type in VIP88129 in the combo box, the python window in ArcMap returns VIP88129.&amp;nbsp; Also, it returns the query with the syntanx that I believe should work in the SelectByAttribute tool, which is "PlanNumber" = 'VIP88129'.&amp;nbsp;&amp;nbsp; Not sure what's going on there.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:48:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46210#M3710</guid>
      <dc:creator>danielchaboya</dc:creator>
      <dc:date>2021-12-10T21:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use user input in Combo Box to perform a Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46211#M3711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would suggest setting a queryVal variable to some default value ("") at the start of the toolbar script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next, in the onEditChange event handler for the combo box,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;declare the queryVal variable as global, and set queryVal to the combobox text.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def onEditChange(self, text):&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; global queryVal &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryVal = str(text)[\CODE]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now the queryVal vaiable is available for use in the onClick handler &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for an Apply button.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is where you would build the query string using queryVal as the value,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and pass it to the geoprocessing tool (and apply the definitionQuery).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Doing it this way also gives the user a moment to inspect what she has typed,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;before the (possibly nonsensical) value is applied as a query....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rereading your post, I see your concern is now with the query not working... oops.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe breaking out the value setting and value applying, as I suggest, would help make the issue clearer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 18:34:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46211#M3711</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-06-07T18:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use user input in Combo Box to perform a Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46212#M3712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Paste the result of the line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;print query&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 18:45:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46212#M3712</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-06-07T18:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use user input in Combo Box to perform a Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46213#M3713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Paste the result of the line:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;print query&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is what is returned ... &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;"PlanNumber" = 'VIP88129'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 21:07:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46213#M3713</guid>
      <dc:creator>danielchaboya</dc:creator>
      <dc:date>2013-06-07T21:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use user input in Combo Box to perform a Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46214#M3714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I've tried this ....&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def onEnter(self): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = mxd.activeDataFrame &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Lots = arcpy.mapping.ListLayers(mxd, "Lots", df) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; plan = SearchPlanNumber_1.value &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = '\"PlanNumber\" = \'' + str(plan) + '\'' &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print plan &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print query &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "LotSelection": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = '"PlanNumber" = \'' + plan + "'" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;If I comment out the SelectByAttribute and df.zoomToSelectedFeatures, I can manipulate the definition query.&amp;nbsp; However,&amp;nbsp; It looks like there is something wrong with the where clause in the SelectByAttribute tool.&amp;nbsp; It fails with the following error ...&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Traceback (most recent call last): &amp;nbsp; File "C:\Users\dchaboya\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{7657B98A-A37F-CA5E-A8E1-C6CEF093100B}\SearchPlanNumber_addin.py", line 32, in onEnter &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query) &amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6435, in SelectLayerByAttribute &amp;nbsp;&amp;nbsp;&amp;nbsp; raise e RuntimeError: Object: Error in executing tool&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Both print statements are returning the values that i'm expecting.&amp;nbsp;&amp;nbsp; For example,&amp;nbsp; if I type in VIP88129 in the combo box, the python window in ArcMap returns VIP88129.&amp;nbsp; Also, it returns the query with the syntanx that I believe should work in the SelectByAttribute tool, which is "PlanNumber" = 'VIP88129'.&amp;nbsp;&amp;nbsp; Not sure what's going on there.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I think your error when attempting to execute the SelectByAttributes is because of the way you are setting the "Lots" layer.&amp;nbsp; If you say the definition query is working correctly, then use the same process to set the layer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead of:&lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;Lots = arcpy.mapping.ListLayers(mxd, "Lots", df)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Use:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;for lyr in arcpy.mapping.ListLayers(mxd, "", df): &amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "Lots": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = '"PlanNumber" = \'' + plan + "'" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jun 2013 13:35:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46214#M3714</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-06-10T13:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Use user input in Combo Box to perform a Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46215#M3715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think your error when attempting to execute the SelectByAttributes is because of the way you are setting the "Lots" layer.&amp;nbsp; If you say the definition query is working correctly, then use the same process to set the layer:&lt;BR /&gt;&lt;BR /&gt;Instead of:&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Lots = arcpy.mapping.ListLayers(mxd, "Lots", df)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Use:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "Lots":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = '"PlanNumber" = \'' + plan + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query)&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks James, that did the trick. One thing, I had to change the name of the input dataset to this ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", query)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;as the variable Lots is no longer being referenced.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:48:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-user-input-in-combo-box-to-perform-a/m-p/46215#M3715</guid>
      <dc:creator>danielchaboya</dc:creator>
      <dc:date>2021-12-10T21:48:49Z</dc:date>
    </item>
  </channel>
</rss>

