Filter the TOP x most occurring between date1 and date2
<p>Please refer to this question: <a href="https://stackoverflow.com/questions/38129734/visual-basic-filter-on-most-occuring-in-acces-databse/38191674?noredirect=1#comment63810629_38191674">Visual Basic, filter on most occuring in Acces Databse</a></p>

<p>So after a long study I have made a form and figured out on how to show the query data in my datagridview1, I made it like this (as a Private sub)</p>

<pre><code>Private Sub FilterNotations(ByVal Top As String)
    Dim TopCat As String

    TopCat = "TOP " &amp; Top


    con.Open()
    Cmd = New OleDbCommand("SELECT " &amp; TopCat &amp; " categorie, COUNT(Id) AS n FROM notations GROUP BY categorie ORDER BY COUNT(Id) DESC", con)
    Cmd.ExecuteNonQuery()
    con.Close()


    Using Cmd = New OleDbCommand("SELECT notations.* FROM notations INNER JOIN (SELECT " &amp; TopCat &amp; " categorie, COUNT(Id) AS n FROM notations GROUP BY categorie ORDER BY COUNT(Id) DESC) AS a ON notations.categorie = a.categorie", con)
        con.Open()
        Using Dad = New OleDbDataAdapter(Cmd)
            Dst.Clear()
            DataGridView1.DataSource = Dst.Tables()
            Dad.Fill(Dst, "notations")
            DataGridView1.DataSource = Dst.Tables(0)
        End Using
    End Using
    con.Close()
End Sub
</code></pre>

<p>The next thing I need some help with is how can I, in addition to how I filter already use the date as in (01-07-16) to get the most occurring between date1 and date2. If some one could give me a gentle push in the right direction that would be kind.</p>

<p><strong>UPDATE#1</strong></p>

<p>I have investigated the clause WHERE and BETWEEN, from the information I could getter from the internet. I came up with this code:</p>

<pre><code>Private Sub FilterNotations(ByVal Top As String)
        Dim TopCat As String

        TopCat = "TOP " &amp; Top


        con.Open()
        Cmd = New OleDbCommand("SELECT " &amp; TopCat &amp; " categorie, COUNT(Id) AS n FROM notations WHERE creation_date BETWEEN #7/2/16# AND #7/5/16# GROUP BY categorie ORDER BY COUNT(Id) DESC", con)
        Cmd.ExecuteNonQuery()
        con.Close()


        Using Cmd = New OleDbCommand("SELECT notations.* FROM notations INNER JOIN (SELECT " &amp; TopCat &amp; " categorie, COUNT(Id) AS n FROM notations WHERE creation_date BETWEEN #7/2/16# AND #7/5/16# GROUP BY categorie ORDER BY COUNT(Id) DESC) AS a ON notations.categorie = a.categorie", con)
            con.Open()
            Using Dad = New OleDbDataAdapter(Cmd)
                Dst.Clear()
                DataGridView1.DataSource = Dst.Tables()
                Dad.Fill(Dst, "notations")
                DataGridView1.DataSource = Dst.Tables(0)
            End Using
        End Using
        con.Close()


    End Sub 
</code></pre>

<p>The problem is that in my datagrid it doesn't show the result I was hoping for.
The SELECT TOP x function works great but it doesn't filter the with date.
could someone please give me a hint.</p>

<p>Kind regards Jordy</p>