Hi, I need to filter beetween two data for "DataProvvedimento": ([DataInizioRicerca] and [DataFineRicerca]), but it doesn't work:
I use format date "dd/mm/yyyy", forse example: DataProvvedimento is 18/06/2024.
[DataInizioRicerca] is the search start date and [DataFineRicerca] is the search end date.
The various controls (ApplicaFiltro button, [CasellaRicercaProv] for another type of search, [DataInizioRicerca] and [DataFineRicerca]) are all on the main form p_CercaProvvedimentoM, while the records are in the subform p_CercaProvvedimentoSubM ([NumeroProvvedimento], [DataProvvedimento], [Cognome], [Nome])
Thank you very much in advance
Code:
Private Sub ApplicaFiltro_Click()
Dim strFilter As String
Dim searchValue As String
Dim dataInizio As Date
Dim dataFine As Date
strFilter = ""
'This is an another search box and it works, but that's another thing
searchValue = Replace(Me![CasellaRicercaProv], "'", "''")
If Not IsNull(Me![CasellaRicercaProv]) And Me![CasellaRicercaProv] <> "" Then
strFilter = "[NumeroProvvedimento] Like '*" & searchValue & "*' " & _
"OR [Cognome] Like '*" & searchValue & "*' " & _
"OR [Nome] Like '*" & searchValue & "*' "
End If
'Filter for data
If IsDate(Me![DataInizioRicerca]) And IsDate(Me![DataFineRicerca]) Then
dataInizio = Me![DataInizioRicerca]
dataFine = Me![DataFineRicerca]
If strFilter <> "" Then
strFilter = strFilter & " AND "
End If
strFilter = strFilter & "((DataProvvedimento >= #" & Format(dataInizio, "dd\/mm\/yyyy") & "#) AND (DataProvvedimento <= #" & Format(dataFine, "dd\/mm\/yyyy") & "#))"
End If
Debug.Print strFilter
'I have the results in the subform p_CercaProvvedimentoSubM
With Me![p_CercaProvvedimentoSubM].Form
.Filter = strFilter
.FilterOn = True
End With
End Sub
I use format date "dd/mm/yyyy", forse example: DataProvvedimento is 18/06/2024.
[DataInizioRicerca] is the search start date and [DataFineRicerca] is the search end date.
The various controls (ApplicaFiltro button, [CasellaRicercaProv] for another type of search, [DataInizioRicerca] and [DataFineRicerca]) are all on the main form p_CercaProvvedimentoM, while the records are in the subform p_CercaProvvedimentoSubM ([NumeroProvvedimento], [DataProvvedimento], [Cognome], [Nome])
Thank you very much in advance