Search between two dates

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
172
Hi, can anyone help, this is my first post regarding Access, I have the code below which works but the only problem is if I put in dates
1641458833950.png
I get nothing even though there is data on that date.

If I enter dates it works fine
1641459138997.png
any help would be great.

VBA Code:
Dim strCriteria, task As String

Me.Refresh
If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
  MsgBox "Please enter a date range", vbInformation, "Date range required"
  Me.StartDate.SetFocus
Else
  strCriteria = "([Date] >=#" & Me.StartDate & " 00:00:00# And [Date] <=#" & Me.EndDate & " 23:59:59#)"
  
  task = "select * from StoresData where (" & strCriteria & ") order by [Date]"
  
  DoCmd.ApplyFilter task
  
End If
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Here is something I used when getting dates into required format
Code:
Public Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Needed for dates in queries as Access expects USA format.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top