Date Range Selection the ODBC connection to database

  • Thread starter Thread starter Steve Mildner
  • Start date Start date
S

Steve Mildner

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 ?
 
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#
 
Back
Top