Button to Select All and Delete selected items in a List Box

Your results are correct, but not going to work for all cases. Because you have ANDS and ORs you will need ()
I agree.

I did not write this function and would not pass back True. That seems confusing. I would just pass back the empty string if nothing is selected. Then check if the function returns ""
I agree.

Therefore, I'm going to forget about this function and use the one you created: GetFilterFromCombo_ListBox.

Now, I can't get it to return the selected values in the list box.

Like I said you have to check all cases which you clearly did not. There are four cases
1. Date Only
2. Date and list criterios
3. Date and list finca
4. date and list criterios and list finca
I agree, but first I will have to obtain the filter, for which I am going to use your function GetFilterFromCombo_ListBox, which I cannot get the correct values. It is for this reason that I request help. I know how to fix the problem of AND and OR with parentheses.

Thank you so much.
 
To be clear I thought what I sent back was the solution. It uses the existing function and just checks for true. I tested all cases and they appear correct.
 
I'm so sorry, but I don't get it works. Could you send the database you are using to test it? Thanks
 
I assume the filter is correct. Is it not. I show it at the bottom of the form.
 

Attachments

I recorded a video, cause you have reason and me too. If you don't use the combo to filter the listobox, it works, but when you use it, the filter doesn't work. Look at the video what I mean. Thanks.
 

Attachments

That is working as designed as far as I can tell. It returns the correct IDSuptipo for Cosecha whichs is 0. I am not seeing the problem. Where is the problem?
TInformeConsultaCriterios TInformeConsultaCriterios

IdConsultaCriterioIdSubtipoNombreSubtipoSubtipoTipo
1969​
50011​
Empresa servicios ParaguasVehiculoGasto
1970​
0​
CosechaCosechaIngreso
1971​
0​
CosechaCosechaIngreso
1972​
0​
CosechaCosechaIngreso
1973​
0​
CosechaCosechaIngreso
1974​
0​
CosechaCosechaIngreso
1975​
0​
CosechaCosechaIngreso
1976​
0​
CosechaCosechaIngreso
1977​
0​
CosechaCosechaIngreso
1978​
0​
CosechaCosechaIngreso
1979​
0​
CosechaCosechaIngreso
1980​
0​
CosechaCosechaIngreso
1981​
0​
CosechaCosechaIngreso
1982​
0​
CosechaCosechaIngreso
1983​
0​
CosechaCosechaIngreso
1984​
0​
CosechaCosechaIngreso
1985​
70002​
PAC OlivarSubvenciónIngreso
 
Captura de pantalla 2024-03-01 192736.png
 
I think I now understand how this works. Once you select your items you want the filter to be based off of the selected items in LstCriteriosAsignados and LstFincasAsignadas not off of the selected items in LstCriteriosAsignados and LstFincas.
Your current code does not try to do that.
 
Your question was pretty confusing if this is what you mean. Your code is not even referencing the correct listboxes and it is looking at items selected and not the items added to the assigned listbox. The code does not even seem to be attempting to do this, if is what you are asking.




Untitled.png


Code:
Private Sub CmdVerInforme_Click()
    Dim CriteriaFilter As String
    Dim FincaFilter As String
    Dim strFilter As String
    If Not IsNull(Me.txtDesdeF) And Not IsNull(Me.txtHastaF) Then
         strFilter = GetBetweenFilter(Me.txtDesdeF, Me.txtHastaF, "Fecha")
    Else
        MsgBox "Es necesario introducir las dos fechas.", vbInformation
        Exit Sub
    End If
 
      CriteriaFilter = GetCriteriaFromPicked(Me.LstCriteriosAsignados, "IdSubtipo")
     ' CriteriaFilter = mdlControlFilters.GetFilterFromControl(Me.LstCriterios, , , 0)
      If CriteriaFilter <> "" Then
          CriteriaFilter = "(" & CriteriaFilter & ")"
          strFilter = strFilter & " AND " & CriteriaFilter
      End If
      
      FincaFilter = GetCriteriaFromPicked(Me.LstFincasAsignadas, "IdFinca")
      If FincaFilter <> "" Then
        If strFilter <> "" Then
           FincaFilter = "(" & FincaFilter & ")"

           strFilter = strFilter & " AND " & FincaFilter
         Else
           strFilter = FincaFilter
         End If
      End If
      
   Me.lblFilter.Caption = strFilter
      
    
End Sub

Private Function GetCriteriaFromPicked(Listbox As Listbox, Criterio As String) As String
   Dim stDocCriteria As String
   Dim i As Integer

   For i = 0 To Listbox.ListCount - 1
     If stDocCriteria = "" Then
       stDocCriteria = Criterio & " = " & Listbox.Column(0, i)
     Else
       stDocCriteria = stDocCriteria & " OR " & Criterio & " = " & Listbox.Column(0, i)
     End If
   Next

   GetCriteriaFromPicked = stDocCriteria
End Function
 

Users who are viewing this thread

Back
Top Bottom