Pulling results between dates

Dragenesis

Registered User.
Local time
Today, 01:34
Joined
Dec 18, 2007
Messages
16
I've linked access to an external database and created a query to pull results from the linked access table that was between certain times on certain dates (i.e. between 11/12/2007 11:01 AM to 12/13/2007 12:01 PM). The query I have thus far is "SELECT * FROM TABLE1 WHERE DATETIME >= #11/12/2007 11:01 AM# AND DATETIME <=#12/13/2007 12:01 PM#". That works, but I want the date and time to be changeable through text fields on a form. Something like "SELECT * FROM TABLE1 WHERE DATETIME >= #forms.form1.startdate forms.form1.starttime# AND DATETIME <= #forms.form1.stopdate forms.form1.stoptime#". The dates are going to be automatically generated according to other parameters but the times are going to be entered manually. How can I accomplish this?
 
There are several ways to do this.
Use parameter queries or build a SQL string and execute it or store it into a query and run it.

To create a SQL string:

Code:
strSql = "SELECT * FROM TABLE1 WHERE DATETIME >= #" & forms.form1.startdate & " " & forms.form1.starttime & "# AND DATETIME <= #" & forms.form1.stopdate & " " & forms.form1.stoptime & "#"

Enjoy!
 

Users who are viewing this thread

Back
Top Bottom