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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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