ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Date Range Selection the ODBC connection to database (https://www.excelbanter.com/excel-programming/287587-date-range-selection-odbc-connection-database.html)

Steve Mildner

Date Range Selection the ODBC connection to database
 
I am having fun and games, trying to take the values entered through a
user form for a start date and end date and then using these dates in
a query.

Has any one ever tried this and how have you passed the values from
the userform into the query ?

onedaywhen

Date Range Selection the ODBC connection to database
 
The SQL syntax will depend on the provider. This example is based on
Jet for Excel and assumes your dates are in textboxes named
txtStartDate and txtEndDate respectively:

Dim strSql As String
Const DATE_FORMAT As String = "dd mmm yyyy"
strSql = "SELECT Amount FROM [EarningsHistory$]" & _
" WHERE DateEffective BETWEEN " & _
" #" & Format(txtStartDate.Text, DATE_FORMAT) & "#" & _
" AND #" & Format(txtEndDate.Text, DATE_FORMAT) & "#"

The resultant query would look like this:

SELECT Amount FROM [EarningsHistory$]
WHERE DateEffective BETWEEN
#01 JAN 2001# AND #31 DEC 2001#

--

(Steve Mildner) wrote in message . com...
I am having fun and games, trying to take the values entered through a
user form for a start date and end date and then using these dates in
a query.

Has any one ever tried this and how have you passed the values from
the userform into the query ?



All times are GMT +1. The time now is 04:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com