Re: SQL Query between 2 dates
- From: Maver1ck666 <Maver1ck666@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Sep 2007 05:28:05 -0700
Thanks for the relpy.
Might sound a bit thick but why would I need to concatenate the dates? The
dates which are being input are in the format of dd/mm/yyyy.
"Allen Browne" wrote:
Concatenate the dates into the string:.
Dim rs AS DAO.Recordset
Dim strSql As String
Const strcJetDate = "\#mm\/dd\/yyyy\#'
strSql = "SELECT Count([Tbl FUNDClosures Completed].CompleteDate)
AS CountOfCompleteDate FROM [Tbl FUNDClosures Completed]
WHERE [Tbl FUNDClosures Completed].CompleteDate Between " & _
Format([Forms]![frm stats closures date]![Date1], strcJetDate) & _
" And " & Format([Forms]![frm stats closures date]![Date2], strcJetDate) &
";"
Set rst = dbEngine(0)(0).OpenRecordset(strSql)
For an explanation of the jet date formatting, see:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html
Note that you could also do this task with DCount() if you wanted to.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Maver1ck666" <Maver1ck666@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B036F441-5952-4269-83EA-7A9B134595A0@xxxxxxxxxxxxxxxx
Hi,
I have a form where a user inputs a "start date" and "end date" (fields
are
called date1 and date2). The form is called frm stats closures date.
When they exit the date2 field, it opens another form which has the
following event procedure on current;
Private Sub Form_Current()
Dim db As Database
Dim rst As Recordset
Dim Qdf As QueryDef
Set db = CurrentDb
Set Qdf = db.CreateQueryDef("")
With Qdf
.SQL = "SELECT Count([Tbl FUNDClosures Completed].CompleteDate) AS
CountOfCompleteDate FROM [Tbl FUNDClosures Completed] WHERE ((([Tbl
FUNDClosures Completed].CompleteDate) Between [Forms]![frm stats closures
date]![Date1] And [Forms]![frm stats closures date]![Date2]));"
Set rst = .OpenRecordset()
End With
Me!FundClosed = rst.Fields("CountOfCompleteDate")
End Sub
Now the problem I am having is that when I try to run the code, it says
Run-time error '3061': Too few parameters. Expected 2.
All the code does is find all the records in Tbl FUNDClosures Completed
which have a completed date between the 2 fields above and returns a
count.
I have looked through the code and if I paste it into a query, it works
fine.
Any suggestions would be greatly apprecuated.
Kind regards,
Maver1ck666
- Follow-Ups:
- Re: SQL Query between 2 dates
- From: Allen Browne
- Re: SQL Query between 2 dates
- References:
- Re: SQL Query between 2 dates
- From: Allen Browne
- Re: SQL Query between 2 dates
- Prev by Date: Re: SQL Query between 2 dates
- Next by Date: Re: Comparing two tables
- Previous by thread: Re: SQL Query between 2 dates
- Next by thread: Re: SQL Query between 2 dates
- Index(es):
Relevant Pages
|