Filter Between Two Dates With Userform

Excel Filter Between Two Dates Using ADODB Recordset


            In this example ,the records between two dates were filtered  with userform. Also filtered data can be copied to other sheet with a button.


We made the filtering between dates by using ADODB Recordset :
Dim con, rs As Object, sorgu As String
Set con = CreateObject("adodb.connection")
#If VBA7 And Win64 Then
con.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.FullName & ";extended properties=""excel 12.0;hdr=yes"""
#Else
con.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.FullName & ";extended properties=""excel 8.0;hdr=yes"""
#End If
ComboBox1.Clear
ComboBox2.Clear
Set rs = CreateObject("adodb.recordset")
sorgu = "select Date from [Page1$] group by Date"
rs.Open sorgu, con, 1, 1
While Not rs.EOF
ComboBox1.AddItem VBA.Format(rs("Date").Value, "dd.mm.yyyy")
ComboBox2.AddItem VBA.Format(rs("Date").Value, "dd.mm.yyyy")
rs.movenext
Wend
rs.Close
con.Close
Set con = Nothing: Set rs = Nothing


excel filter between two dates adodb

1 comment:

  1. hello, Thanks for sharing.

    I am getting an error message "Type mismatch, error 13"

    Please help to solve. Thanks

    ReplyDelete