Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8956715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:50:41+00:00 2026-06-15T14:50:41+00:00

I have a very simple problem. I have a couple of datepicker controls on

  • 0

I have a very simple problem. I have a couple of datepicker controls on my VB.NET form and users select “startDate” and “endDate”, and all rows from the related table are displayed which have an orderDate between the user’s selected start and end dates.

The following is the relevant code:

Private Sub generate_report_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles generate_report.Click
    Try
        Dim con As New OleDb.OleDbConnection
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\KHMSDB.accdb"
        con.Open()
        Dim sql As String
        Dim selected As String = ""
        Dim ds As DataSet = New DataSet

        Dim adapter As New OleDb.OleDbDataAdapter
        sql = "SELECT OrderDate AS `Order Date and Time`, Items AS `Ordered Items` FROM Orders WHERE Format(Orders.OrderDate,'mm/dd/yyyy') >= #" + startDate.Value.Date + "# AND Format(Orders.OrderDate,'mm/dd/yyyy') <= #" + endDate.Value.Date + "#"
        adapter.SelectCommand = New OleDb.OleDbCommand(sql, con)
        adapter.Fill(ds)
        gridReport.DataSource = ds.Tables(0)

    Catch ex As Exception

        MsgBox("Operation failed. " + ex.ToString)

    End Try

If I save a new row in the database under today’s date, and I leave the “start” and “end” dates both as the default date (i.e. today’s date), it doesn’t show the new row I just saved. The new row entered today only shows up if I move the “start date” up to the 30th of November. Then I add a new row with date 12th December. Again, it won’t show up when I select the end date to be >= 12 December, it’ll only show up when I move the start date up to 1st December. I decided to enter a row dated 21st November, and running the query with start and end date both on 21st November shows up that row. I then entered a new row in January 8th.. and now any combination of moving up startDate and or moving down endDate just doesn’t display the January order. What’s going on?? I’ve actually already tried this code out before in November and it worked perfectly fine!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:50:42+00:00Added an answer on June 15, 2026 at 2:50 pm

    What could be the issue with this is the string format. I’m not sure if Access will convert the string to a Date and then compare or convert the Date to a string and then compare. You can try this:

    Format(Orders.OrderDate,'mm/dd/yyyy') >= Format(#" + startDate.Value.Date + "#,'mm/dd/yyyy')

    Or you could always just use the date directly,

    OrderDate >= #" + startDate.Value.Date + "#"

    Edit:, to do my due diligence, you really should be doing the query like this

    OrderDate >= @StartDate
    

    Then add this code

    adapter.Parameters.Add("@StartDate", startDate.Value.Date);
    

    Using parameters is important for robust code and to avoid the dreaded SQL injection attack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple problem. I have a data frame with multiple rows
I have a very simple problem but cannot find a nice solution. I have
I have a very simple problem, but I can't seem to solve it. I
I have a very simple C# DataTable problem that I cannot seem to wrap
I have a very simple JavaScript/jquery code which won't just work correctly. The problem
I have made a very simple AppleScript to close tabs in Safari. The problem
I have a big problem with very simple code. I need to get a
I have a problem with OpenGl ES 2.0. I've designed a very simple framework
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have a terrible problem that hopefully has a very simple answer. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.