'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 '" & StrOberKat & "' im Postleitzahlbereich '" & StrPLZ & "' " & StrText & "werden angezeigt", vbOKOnly, "Hinweis" pDefQuery.DefinitionExpression = "PLZ = '" & StrPLZ & "'" End If 'Refresh pMxDocument.ActiveView.Refresh pMxDocument.UpdateContents End Sub
ComboBox3.Clear ComboBox3.Value = "Bitte Postleitzahl wählen" ComboBox3.AddItem "44795" 'Bochum-Weitmar ComboBox3.AddItem "44797" 'Bochum-Weitmar ComboBox3.AddItem "44799" 'Bochum ComboBox3.AddItem "44801" 'Bochum-Querenburg ComboBox3.AddItem "44803" 'Bochum-Steinkuhl ComboBox3.AddItem "45527" 'Hattingen ComboBox3.AddItem "58454" 'Witten ComboBox3.AddItem "58455" 'Witten ComboBox3.AddItem "58456" 'Witten-Herbede ComboBox3.AddItem "0" '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"
Solved! Go to Solution.
You don't need a new field, you just need to write the definition query using the proper syntax:
pDefQuery.DefinitionExpression = "PLZ = '" & StrPLZ & "'"
If PLZ is a string field then this query is correct. If PLZ is a numeric field then remove the single quotes around the value:
pDefQuery.DefinitionExpression = "PLZ = " & StrPLZ