We help IT Professionals succeed at work.
Get Started

Problem passing Parameters using DAO QueryDef

Last Modified: 2013-12-25
I am trying to pass a start and end date to a parameter query using DAO querydef. Even though I assume I have passed the parameters in the following code, I am still being prompted to enter the dates. What am I missing?
SELECT FROM tblProjectControl " _
& "tblProjectControl.TargetDT, " _
& "tblProjectControl.SomeField2, " _
& "tblProjectControl.SomeField3 " _ 
& "WHERE tblProjectControl.targetID " _
& ">=[StartDT] And <= [EndDT];"

Private Sub cmdBuildReleaseReport_Click()
'On Error GoTo Err_cmdBuildReleaseReport_Click
    Dim StartDT As Date
    Dim EndDT As Date
    StartDT = cboReleaseMonth.Column(2)
    EndDT = cboReleaseMonth.Column(3)

    Dim DB As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim rs As DAO.Recordset
    Set DB = CurrentDb
    Set qdf = DB.QueryDefs("qryRpt_ByRelease")
    qdf.Parameters("StartDT") = StartDT
    qdf.Parameters("EndDT") = EndDT
    Set rs = qdf.OpenRecordset()
    With rs
        DoCmd.OpenQuery "qryRpt_ByRelease"
    End With

End Sub

Open in new window

Watch Question
Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE