473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to search by date range in Access?

Hi all,

I am trying to create a form that will select records by date range. The form contains 2 textboxes, with pop-up calendars to select dates. I managed to come up with this code, however, it's not working. Whenever I run the code, my database just goes blank, as though it's selecting something that is not in the records.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command16_Click()
  2.     Dim Task As String
  3.     Dim startDate As Date
  4.     Dim endDate As Date
  5.  
  6.     startDate = DateValue(Me.Text12)
  7.     endDate = DateValue(Me.Text14)
  8.  
  9.     Task = "SELECT * FROM Final WHERE Final.Timestamp BETWEEN #" & Format$(startDate, "dd\/mm/yyyy") & "# AND #" & Format$(endDate, "dd\/mm\/yyyy") & "#;"
  10.     Debug.Print Task
  11.     Me.RecordSource = Task
  12. End Sub
Could this be because my timestamp column actually contains both the date and time, that's why the search is unable to happen? If so, how do I work around this?
Dec 1 '14 #1
1 6796
jimatqsi
1,271 Expert 1GB
Shawn,
I see you are formatting the date as dd\/mm\/yyyy instead of dd/mm/yyyy. I don't recognize that \ as meaning anything. I think if you remove it in both date formats the code will work.

The thing about date fields with time include is that the date/time value is greater than the date value alone. So you need to 1)know that every row has a time included and none are 0:00:00 and 2) you have to bump the ending date in your search up by 1 day.

Oh, one more thing. Do yourself a favor right now and commit to never using the automated names for your objects. Always give your objects recognizable names. "Command16" probably tells nothing about the function of that command button. When you, or someone else, looks at this code later, they'll have to search the form to figure out what Command16 is.

Jim
Dec 1 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: fonzie | last post by:
Is there any way to include two unbound text boxes (for a start date and end date) to a filter-by-form? The users may want to filter by several different fields and they may want to include a date...
0
by: rdemyan via AccessMonster.com | last post by:
I have a need to highlight a date range in a bar chart. If the "highlighting" is accomplished by changing the bar column color for the specific months in the date range, that would be great. ...
1
by: flumpuk | last post by:
Hi My job currently requires me to enter data from 300+ forms a month. The system which we used in Excel was slow , and theprevious guy had three workbooks for this job . I have created...
1
by: kappa | last post by:
I have a problem in ALL my queries when I run a specific date range. Access always crashes when I view in Datasheet view. This doesn't occur if it's a parameter query and I am prompted to enter the...
0
by: mwalsh62 | last post by:
Greetings all! My first post here, and my mind is pudding at this point (any flavor you like)! I have been searching for days, and still can't figure out the proper syntax that I require. This...
12
by: jamieboy86 | last post by:
Hi Everyone, I'm new here and to access as well, The problem I'm having right now is that I made a Query that upon the input of a date, it will search for the last purchase I made and at what...
19
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the...
3
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a...
1
by: kffacs | last post by:
Multiple rows based on a date range I have an MSAccess 2007 DB to record our employees Personal Days Off (PDO). Until now I have only had a form to record each single day taken. This results in...
0
by: LBinGA | last post by:
Hello! I am using Access 2010 and I have an Unbound Form (FrmFilter) that filters a report by (up to) 7 criteria using the code below, which works beautifully. I would like to add 2 additional...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.