<?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: Problem with WhereClause/DefinitionExpression - SQL statement (VBA) in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751503#M19922</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: Neil&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You don't need a new field, you just need to write the definition query using the proper syntax:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "PLZ = '" &amp;amp; StrPLZ &amp;amp; "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If PLZ is a string field then this query is correct.&amp;nbsp; If PLZ is a numeric field then remove the single quotes around the value:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "PLZ = " &amp;amp; StrPLZ&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Jun 2012 12:23:21 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2012-06-11T12:23:21Z</dc:date>
    <item>
      <title>Problem with WhereClause/DefinitionExpression - SQL statement (VBA)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751501#M19920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;SPAN&gt;Original User: &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:koboldmaquis@yahoo.de" rel="nofollow noopener noreferrer" target="_blank"&gt;koboldmaquis@yahoo.de&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Original Date: 2012-06-08T18:03:01-0600&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;my WhereClause/DefinitionExpression - SQL statement isn't working. I'm getting the values for the SQL statement out of the ComboBox3 (UserForm) via the variable StrPLZ = ComboBox3.Value. I'm trying to use this variable in the SQL statement, but i get in ArcMap the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ArcMap Drawing Error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;One or more layers failed to draw:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;POI: An invalid SQL statement was used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My guess is, that the programm cant query/compare the string variable (StrPLZ) with the long-datatype field of the attribute table (PLZ) (see highlighted code below, Screenshot of Table). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can anybody please help me&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;'Definition Query: Suche von POI Ã¼ber die Postleitzahl (Name des Buttons im GUI: POI suchen)
Private Sub CommandButton3_Click()

'Connect Schnittstellen
Dim pMxDocument As IMxDocument
Set pMxDocument = ThisDocument
Dim pMap As IMap
Set pMap = pMxDocument.FocusMap
Dim pLayer0 As ILayer
Set pLayer0 = pMap.Layer(0)

'Schnittstelle wechseln (QueryInterface),
'um fÃ¼r die Abfrage notwendige Eigenschaften und Methoden zu erhalten
Dim pDefQuery As IFeatureLayerDefinition
Set pDefQuery = pLayer0

'Anwendereingaben aus der ComboBox3, ComboBox4 und ComboBox5 in Variable schreiben
'benÃ¶tigt, damit das Programm 'weiÃ?', welche Features (POI) angezeigt werden sollen
Dim StrPLZ As String
Dim StrOberKat As String
Dim StrUnKat As String
StrPLZ = ComboBox3.Value
StrOberKat = ComboBox4.Value
StrUntKat = ComboBox5.Value

'Variable fÃ¼r Message Boxen deklarieren (Name des PLZ-Bereichs)
Dim StrText As String
StrText = TextBox1.Text

'gegebenenfalls vorhandene Auswahl entfernen
pDefQuery.DefinitionExpression = ""

'Definition Query durchfÃ¼hren
If StrPLZ = "Bitte Postleitzahl wÃ¤hlen" Then
MsgBox "Sie haben keine Auswahl getroffen. Alle POI werden angezeigt", vbOKOnly + vbExclamation, "Auswahl treffen"
pDefQuery.DefinitionExpression = ""
ElseIf StrUntKat = "Optional: Unterkategorie wÃ¤hlen" Then
MsgBox "Alle POI in der Oberkategorie '" &amp;amp; StrOberKat &amp;amp; "' im Postleitzahlbereich '" &amp;amp; StrPLZ &amp;amp; "' " &amp;amp; StrText &amp;amp; "werden angezeigt", vbOKOnly, "Hinweis"
pDefQuery.DefinitionExpression = "PLZ = '" &amp;amp; StrPLZ &amp;amp; "'"
End If


'Refresh
pMxDocument.ActiveView.Refresh
pMxDocument.UpdateContents

End Sub&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;ComboBox3.Clear
ComboBox3.Value = "Bitte Postleitzahl wÃ¤hlen"
ComboBox3.AddItem "44795"&amp;nbsp;&amp;nbsp; 'Bochum-Weitmar
ComboBox3.AddItem "44797"&amp;nbsp;&amp;nbsp; 'Bochum-Weitmar
ComboBox3.AddItem "44799"&amp;nbsp;&amp;nbsp; 'Bochum
ComboBox3.AddItem "44801"&amp;nbsp;&amp;nbsp; 'Bochum-Querenburg
ComboBox3.AddItem "44803"&amp;nbsp;&amp;nbsp; 'Bochum-Steinkuhl
ComboBox3.AddItem "45527"&amp;nbsp;&amp;nbsp; 'Hattingen
ComboBox3.AddItem "58454"&amp;nbsp;&amp;nbsp; 'Witten
ComboBox3.AddItem "58455"&amp;nbsp;&amp;nbsp; 'Witten
ComboBox3.AddItem "58456"&amp;nbsp;&amp;nbsp; 'Witten-Herbede
ComboBox3.AddItem "0"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Keine PLZ Zuordnung mÃ¶glich

ComboBox4.Clear
ComboBox4.Value = "Optional: Oberkategorie wÃ¤hlen"
ComboBox4.AddItem "Ã?ffentliche Einrichtungen"
ComboBox4.AddItem "Wohnheime"
ComboBox4.AddItem "Nahversorgung"
ComboBox4.AddItem "Dienstleistungen"
ComboBox4.AddItem "Gesundheitswesen"
ComboBox4.AddItem "Freizeiteinrichtungen/Sport/Wellness"
ComboBox4.AddItem "Gastronomie"
ComboBox4.AddItem "Kultur/Unterhaltung"
ComboBox4.AddItem "Sonstige"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]15079[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]15080[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:52:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751501#M19920</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T16:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with WhereClause/DefinitionExpression - SQL statement (VBA)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751502#M19921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ok i found a solution...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;just add a new field in the attribute table of your data, set the datatype to TEXT, fill the column with the numbers from the LONG field.. u get now string numbers which u can compare in the vba sql statement&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Jun 2012 11:45:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751502#M19921</guid>
      <dc:creator>MauriceSchoenert</dc:creator>
      <dc:date>2012-06-10T11:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with WhereClause/DefinitionExpression - SQL statement (VBA)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751503#M19922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: Neil&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You don't need a new field, you just need to write the definition query using the proper syntax:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "PLZ = '" &amp;amp; StrPLZ &amp;amp; "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If PLZ is a string field then this query is correct.&amp;nbsp; If PLZ is a numeric field then remove the single quotes around the value:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "PLZ = " &amp;amp; StrPLZ&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jun 2012 12:23:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751503#M19922</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2012-06-11T12:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with WhereClause/DefinitionExpression - SQL statement (VBA)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751504#M19923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You don't need a new field, you just need to write the definition query using the proper syntax:&lt;BR /&gt;&lt;BR /&gt;pDefQuery.DefinitionExpression = "PLZ = '" &amp;amp; StrPLZ &amp;amp; "'"&lt;BR /&gt;&lt;BR /&gt;If PLZ is a string field then this query is correct.&amp;nbsp; If PLZ is a numeric field then remove the single quotes around the value:&lt;BR /&gt;&lt;BR /&gt;pDefQuery.DefinitionExpression = "PLZ = " &amp;amp; StrPLZ&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mmmh, thx, I'll try it. It seems so easy, if u know it.. i was searching the inet and ArcGIS help pages for hours&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is that SQL Syntax (in VBA) basic knowledge or why is there no reference in ArcGIS Desktop Help Center &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jun 2012 16:04:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751504#M19923</guid>
      <dc:creator>MauriceSchoenert</dc:creator>
      <dc:date>2012-06-11T16:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with WhereClause/DefinitionExpression - SQL statement (VBA)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751505#M19924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, the statement &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "PLZ = " &amp;amp; StrPLZ&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; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;works,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but what is the syntax for:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "PLZ = '" &amp;amp; StrPLZ &amp;amp; "' AND Kategorie = '" &amp;amp; StrOberKat &amp;amp; "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "PLZ = '" &amp;amp; StrPLZ &amp;amp; "' AND Kategorie = '" &amp;amp; StrOberKat &amp;amp; "' AND Unterkategorie = '" &amp;amp; StrUntKat &amp;amp; "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried something like this: pDefQuery.DefinitionExpression = "PLZ = " &amp;amp; StrPLZ&amp;nbsp; AND Kategorie = '" &amp;amp; StrOberKat &amp;amp; "'" which isnt working&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PLZ is numeric, StrPLZ is string, Kategorie is string, StrOberKat is string, Unterkategorie is string, StrUntKat is string&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sorry, I'm not familiar with sql in vba, thank u for ur support!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jun 2012 17:12:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751505#M19924</guid>
      <dc:creator>MauriceSchoenert</dc:creator>
      <dc:date>2012-06-11T17:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with WhereClause/DefinitionExpression - SQL statement (VBA)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751506#M19925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: Neil&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If the field type is text then the value must be enclosed in single quotes.&amp;nbsp; If the field is numeric then the value is not enclosed in single quotes.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jun 2012 17:33:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751506#M19925</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2012-06-11T17:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with WhereClause/DefinitionExpression - SQL statement (VBA)</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751507#M19926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;yes, very confusing&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;correct:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "Kategorie = '" &amp;amp; StrOberKat &amp;amp; "' AND PLZ =&amp;nbsp; " &amp;amp; StrPLZ &amp;amp; ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pDefQuery.DefinitionExpression = "PLZ = " &amp;amp; StrPLZ &amp;amp; " AND Kategorie = '" &amp;amp; StrOberKat &amp;amp; "' AND Unterkategorie = '" &amp;amp; StrUntKat &amp;amp; "'"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jun 2012 18:31:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-with-whereclause-definitionexpression-sql/m-p/751507#M19926</guid>
      <dc:creator>MauriceSchoenert</dc:creator>
      <dc:date>2012-06-11T18:31:23Z</dc:date>
    </item>
  </channel>
</rss>

