Hello,
We like to search on some dates we selected from the checkbox's in a loop
but seems it still keeps some dates out from the loop
the DB m_endtime has the date/time value
and we save our data as a date only like: day-month-year
'Got 12 checkboxs that has tag with 01 till 12 for the months
For Each Ctrl In frmStatistics.Controls
If TypeName(Ctrl) = "CheckBox" Then
If Ctrl.value = True Then 'if the checkbox is checked
GetStatistics Ctrl.Tag & "-" & "20" 'must looks like 05-20 ect... month-year
End If
End If
Next Ctrl
Function GetStatistics (txt as string)
Dim ws As Worksheet ' as per WsName
Dim intColIndex As Integer
Set DBcon = New ADODB.Connection
Set DBrs = New ADODB.Recordset
Set ws = Worksheets("Sheet4") ' load data into our sheet
PathDB = PathToFile(database)
Dim dt As Date
constring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathDB & ";Jet OLEDB:Database Password='" & pass & "';Mode=Share Exclusive"
DBcon.Open (constring)
Dim tt, tx As String
DBQuery = "SELECT * FROM TBL_ImportList " & _
"WHERE m_endtime LIKE ""%" & Format(txt, "mm-yy") & "%""" ' here we get a part of our search not all of them
DBrs.Open DBQuery, DBcon
For intColIndex = 0 To DBrs.Fields.Count - 1
ws.Cells(1, intColIndex + 1).value = DBrs.Fields(intColIndex).Name ' name values in row A1
Next
If Not DBrs.EOF Then
ws.Range("A2").CopyFromRecordset DBrs ' Data search return into sheet4
End If
DBrs.Close
DBcon.Close
Set DBrs = Nothing
Set DBcon = Nothing
End Function
Database can be found here: https://drive.google.com/file/d/1kcWCKdrQX7Er47Ae7hz0P5bltSdkmGWz/view?usp=sharing
EDIT:
Seems when found results it clears the sheet? over and over again...
Demo file has been added.
Thanks