We help IT Professionals succeed at work.
Get Started

using monthcalendar to query

Sean Rhudy
Sean Rhudy asked
Last Modified: 2010-04-23
Hello, I have a form called journal.vb, right now as it is, the btnSearch button is clicked and any records in the current month and year are displayed in a datagrid.  The field in the database I am using is called "pdate".  I have a monthcalendar named "monthcalendar1" I would like the user to be able to choose a date on the calendar, then either choose year, month, or week.  Of course I would no longer have a search button, just 3 buttons named year, month, and week.  If the date 12/03/2006 is selected on the calendar, and the user clicks year, all records with a pdate in 2006 will be shown, if they click month, all records with a pdate of december 2006 will be shown, and if week is clicked, all records with a pdate in that week will be shown.  Here is the code I am working with:

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim Da As OleDb.OleDbDataAdapter

            Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/backup/receiptprogram/receiptmanagement/receipt.mdb"
            Cmd.Connection = Con
        Catch ex As Exception
        End Try

            Cmd.CommandText = "SELECT * FROM Receiptinfo WHERE Month([pdate]) = Month(Now()) AND Year([pdate]) = Year(Now()) AND DatePart(ww,[pdate])=DatePart(ww,Now())"

            Cmd.CommandType = CommandType.Text
            Da = New OleDb.OleDbDataAdapter(Cmd)
            Datagridjournal.DataSource = JournalDataSet.Receiptinfo

        Catch ex As Exception
            Cmd.Connection = Nothing
        End Try
    End Sub
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE