Solved Query which pulls Values from a forms Textboxes and Displays data between the two Values in those Textboxes (1 Viewer)

Bean Machine

Member
Local time
Today, 12:13
Joined
Feb 6, 2020
Messages
102
Hi All!

I am struggling to find a way to do this. Essentially I want a query to figure out what is in two textboxes on a form and display only the data that occurs between those two values. In this case between two years as seen in the attached image below.

year textbox example.png

Likely something using the Between function and the Like function, but I am at a loss. Any help would be greatly appreciated.
 

cheekybuddha

AWF VIP
Local time
Today, 17:13
Joined
Jul 21, 2014
Messages
2,280
SQL:
SELECT
  *
FROM YourTable
WHERE DateField >= DateSerial([cboYearStart], 1, 1)
  AND DateField < DateSerial([cboYearEnd] + 1, 1, 1);
 

June7

AWF VIP
Local time
Today, 08:13
Joined
Mar 9, 2014
Messages
5,473
BETWEEN AND is inclusive for both ends. So build end date for 12/31/xxxx, not 1/1/xxxx+1
 

June7

AWF VIP
Local time
Today, 08:13
Joined
Mar 9, 2014
Messages
5,473
or use: ... <= DateSerial([cboYearEnd], 12, 31)

or:

DateField BETWEEN DateSerial([cboYearStart, 1, 1) AND DateSerial([cboYearEnd), 12, 31)

or simply:

Year(DateField) BETWEEN [cboYearStart] AND [cboYearEnd]

An advantage is don't have to be concerned with date structure if not using U.S. date format.
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 17:13
Joined
Jul 21, 2014
Messages
2,280
or use: ... <= DateSerial([cboYearEnd], 12, 31)

or:

DateField BETWEEN DateSerial([cboYearStart, 1, 1) AND DateSerial([cboYearEnd), 12, 31)
These miss out on anything after 12:00:01am 31st December until midnight on New Year's day.
 
Last edited:

June7

AWF VIP
Local time
Today, 08:13
Joined
Mar 9, 2014
Messages
5,473
Only if DateField is saving time components, otherwise works for me.

Granted, I seldom have need to save time components so I did overlook this.
 

ebs17

Well-known member
Local time
Today, 18:13
Joined
Feb 7, 2020
Messages
1,946
Code:
or simply:
Year(DateField) BETWEEN [cboYearStart] AND [cboYearEnd]
Simple but slow.

A leaflet should be mandatory here: This suggestion does not allow the use of a possibly existing index and therefore gives performance away.
 

Users who are viewing this thread

Top Bottom