3 combobox and multiple query

894
6
05-17-2010 09:02 AM
BarbaraRossi
New Contributor
Hi,
I created a form with number 3 combobox.
when you press the search button, I do a search on the basis of
combobox choice, only 1 or 2 or all three.
This is the code I wrote and it works perfectly but only for a
case (Only one combobox is choice)
How can I add other combinations?
Can someone help me?
Thank you.

Private Sub cmdSearch_Click()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pMaps As IMaps
    Set pMaps = pMxDoc.Maps
    Dim pCatastoStradeMappa As IMap
    Set pCatastoStradeMappa = pMaps.Item(0)
    Dim pInterventiLayerDef As IFeatureLayerDefinition
    Set pInterventiLayerDef = pCatastoStradeMappa.Layer(0)

    If cboStrada = " " And cboCodice = " " And cboProvincia = " " And cboSoggetto = " " Then
        MsgBox "Scegli almeno un parametro di ricerca"
    End If

    Dim strQuery As String
    strQuery = "Nome_Strada= '" & cboStrada.Text & "' or Codice = '" & cboCodice.Text & "'or Provincia = '" & cboProvincia.Text & "'"
    Dim pCatastoStradeActiveView As IActiveView
    Set pCatastoStradeActiveView = pCatastoStradeMappa
   
    Dim pCatastoStradeLayer As IFeatureSelection
    Set pCatastoStradeLayer = pCatastoStradeMappa.Layer(0)
   
    Dim pFilter As IQueryFilter
    Set pFilter = New QueryFilter
    pFilter.WhereClause = strQuery
    pCatastoStradeLayer.SelectFeatures pFilter, esriSelectionResultNew, False

.......
0 Kudos
6 Replies
BarbaraRossi
New Contributor
hello,
I better explain what it will do.
Attached are two photos that you show what can I do now.
I would however be able to do a search that lets you select any value of
any combobox and not just one.

I would add these other queries:
strQuery = "Nome_Strada= '" & cboStrada.Text & "' and Codice = '" & cboCodice.Text & "'and Provincia = '" & cboProvincia.Text & "'"

or

strQuery = "Nome_Strada= '" & cboStrada.Text & "' or Codice = '" & cboCodice.Text & "'and Provincia = '" & cboProvincia.Text & "'"

I tried with if then else cycles but the result is always and only, the first choice in the cycle if.
Sorry if I was not too clear.

Thanks.
0 Kudos
JamesCrandall
MVP Frequent Contributor
hello,
I better explain what it will do.
Attached are two photos that you show what can I do now.
I would however be able to do a search that lets you select any value of
any combobox and not just one.

I would add these other queries:
strQuery = "Nome_Strada= '" & cboStrada.Text & "' and Codice = '" & cboCodice.Text & "'and Provincia = '" & cboProvincia.Text & "'"

or

strQuery = "Nome_Strada= '" & cboStrada.Text & "' or Codice = '" & cboCodice.Text & "'and Provincia = '" & cboProvincia.Text & "'"

I tried with if then else cycles but the result is always and only, the first choice in the cycle if.
Sorry if I was not too clear.

Thanks.


I think you mean you'd like If/ElseIf statements based upon the values in the ComboBoxes?  Maybe something like:

If Not cboStrada.Text = "" Then
  strQuery = "Nome_Strada = '" & cboStrada.Text & "'"
ElseIf Not cboCodice.Text = "" Then
 strQuery = "Codice = '" & cboCodice.Text & "'"
ElseIf Not cboProvincia.Text = "" Then
 strQuery = "Provincia = '" & cboProvincia.Text & "'"
Else
 msgBox("No values set in any of the ComboBoxes!")
End If
0 Kudos
BarbaraRossi
New Contributor
Hi James,
thank you very much for your reply.
I tried your solution, I'd already done myself.
The problem is that always runs

  strQuery = "Nome_Strada = '" & cboStrada.Text & "'"

ie the first statement.
Even the message box appears when I make any choice.
Maybe the rest of the code is wrong.
I try to put everything.
thanks again.
Barbara

*************************************************************************
Private Sub cmdSearch_Click()

    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pMaps As IMaps
    Set pMaps = pMxDoc.Maps
    Dim pCatastoStradeMappa As IMap
    Set pCatastoStradeMappa = pMaps.Item(0)
    Dim pInterventiLayerDef As IFeatureLayerDefinition
    Set pInterventiLayerDef = pCatastoStradeMappa.Layer(0)

Dim strQuery As String

If Not cboStrada.Text = "" Then
  strQuery = "Nome_Strada = '" & cboStrada.Text & "'"
ElseIf Not cboCodice.Text = "" Then
strQuery = "Codice = '" & cboCodice.Text & "'"
ElseIf Not cboProvincia.Text = "" Then
strQuery = "Provincia = '" & cboProvincia.Text & "'"
Else
MsgBox ("No values set in any of the ComboBoxes!")
End If

   
    Dim pCatastoStradeActiveView As IActiveView
    Set pCatastoStradeActiveView = pCatastoStradeMappa
   
    Dim pCatastoStradeLayer As IFeatureSelection
    Set pCatastoStradeLayer = pCatastoStradeMappa.Layer(0)
   
'Create a QueryFilter for the first argument of the SelectFeatures method
    Dim pFilter As IQueryFilter
    Set pFilter = New QueryFilter

    pFilter.WhereClause = strQuery

'Make the selection with the SelectFeatures method
    pCatastoStradeLayer.SelectFeatures pFilter, esriSelectionResultNew, False


'Create an RGB color and set its Red property to 200
    Dim pRedColor As IRgbColor
    Set pRedColor = New RgbColor
    pRedColor.Red = 200
   
'Set the states layer's Selectioncolor property = the RgbColor object
    Set pCatastoStradeLayer.SelectionColor = pRedColor
   

Dim pLayer As IFeatureLayer
Dim pFSel As IFeatureSelection
Set pLayer = pCatastoStradeMappa.Layer(0)
Set pCatastoStradeLayer = pLayer

'Get the selected features
Dim pSelSet As ISelectionSet
Set pSelSet = pCatastoStradeLayer.SelectionSet

Dim pEnumGeom As IEnumGeometry
Dim pEnumGeomBind As IEnumGeometryBind

Set pEnumGeom = New EnumFeatureGeometry
Set pEnumGeomBind = pEnumGeom

pEnumGeomBind.BindGeometrySource Nothing, pSelSet

Dim pGeomFactory As IGeometryFactory
Set pGeomFactory = New GeometryEnvironment

Dim pGeom As IGeometry
Set pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom)

pMxDoc.ActiveView.Extent = pGeom.Envelope
pMxDoc.ActiveView.Refresh

End Sub

***************************************************************************
Private Sub cmdReset_Click()
    cboStrada.Text = " "
    cboCodice.Text = " "
    cboProvincia.Text = " "
    cboSoggetto.Text = " "
End Sub

***************************************************************************
Private Sub UserForm_Initialize()
'così inserisco oggetti nei vari menù a tendina
    cboStrada.AddItem "SP424"
    cboStrada.AddItem "SP001"
    cboCodice.AddItem "06BP"
    cboCodice.AddItem "03A"
    cboCodice.AddItem "PR02"
    cboProvincia.AddItem "AN"
    cboProvincia.AddItem "PU"
    cboSoggetto.AddItem "S1"
    cboSoggetto.AddItem "S2"
    cboSoggetto.AddItem "S3"

End Sub
0 Kudos
JamesCrandall
MVP Frequent Contributor
Barbara,

You could try getting the SelectedText or SelectedValue of the Combobox instead of trying to get .Text...

Something like this (I can't remember the exact statment to use and will have to test tomorrow):

If Not cboStrada.SelectedText = "" Then  ' Or try cboStrada.SelectedValue
   strQuery = "Nome_Strada = '" & cboStrada.Text & "'"
ElseIf Not cboCodice.SelectedText = "" Then
   strQuery = "Codice = '" & cboCodice.Text & "'"
ElseIf Not cboProvincia.SelectedText = "" Then
   strQuery = "Provincia = '" & cboProvincia.Text & "'"
Else
   MsgBox ("No values set in any of the ComboBoxes!")
End If
0 Kudos
BarbaraRossi
New Contributor
Hi James,
i don't know how to thank yuo.
without your help I would not have ever made.
I write the correct code for all who need it.
thanks, thanks, thanks
Barbara

If cboCodice.SelText <> "" And cboStrada.SelText <> "" And cboProvincia.SelText = "" Then
    strQuery = "Nome_Strada= '" & cboStrada.Text & "' and Codice = '" & cboCodice.Text & "'"
ElseIf cboCodice.SelText = "" And cboStrada.SelText <> "" And cboProvincia.SelText = "" Then
    strQuery = "Nome_Strada = '" & cboStrada.Text & "'"
ElseIf cboCodice.SelText = "" And cboStrada.SelText = "" And cboProvincia.SelText <> "" Then
    strQuery = "Provincia = '" & cboProvincia.Text & "'"
ElseIf cboCodice.SelText <> "" And cboStrada.SelText <> "" And cboProvincia.SelText <> "" Then
    strQuery = "Nome_Strada= '" & cboStrada.Text & "' and Codice = '" & cboCodice.Text & "'and Provincia = '" & cboProvincia.Text & "'"
ElseIf cboCodice.SelText <> "" And cboStrada.SelText = "" And cboProvincia.SelText = "" Then
    strQuery = "Codice = '" & cboCodice.Text & "'"
ElseIf cboCodice.SelText <> "" And cboStrada.SelText = "" And cboProvincia.SelText <> "" Then
    strQuery = "Provincia= '" & cboProvincia.Text & "' and Codice = '" & cboCodice.Text & "'"
ElseIf cboCodice.SelText = "" And cboStrada.SelText <> "" And cboProvincia.SelText <> "" Then
    strQuery = "Provincia= '" & cboProvincia.Text & "' and Nome_Strada = '" & cboStrada.Text & "'"
Else
    MsgBox ("No values set in any of the ComboBoxes!")
End If
0 Kudos
JamesCrandall
MVP Frequent Contributor
Hi James,
i don't know how to thank yuo.
without your help I would not have ever made.
I write the correct code for all who need it.
thanks, thanks, thanks
Barbara



I'm happy to hear you got it working, Barbara!
0 Kudos