I have a stored query below in Access call "1PreviousEWBS":
SELECT f.ewbs AS EWBS, SUM(f.[total hours]) AS [Total Hours], SUM(f.[total cost]) AS [Total Cost], T.description AS Activity, T.AWBS AS AWBS
FROM FindHrCostByEWBS AS f, AllProjectsCodes AS T
WHERE (f.project)=Forms!x!cboProjects
And f.[period end date]<Forms!x!cboDate
And f.ewbs=T.oldewbs
GROUP BY f.ewbs,T.description, T.AWBS;
Bascially I wrote this so users can use the combo box to select their data.
But now, I am curious to see how can i set the parameters directly through VBA. I had something like this set up.
Sub TestSeePreviousData
Dim rS As DAO.Recordset
Dim db As DAO.Database
Dim queryDef As DAO.queryDef
Dim ProjectNumber As String
Dim FiscalDate As Date
FiscalDate = #4/25/2014#
Set db = CurrentDb
Set queryDef = db.QueryDefs("1PreviousEWBS")
'Parameter 0 is to input the Project number
queryDef.Parameters(0) = "173221"
'Parameter 1 is to give the fiscal period end date
queryDef.Parameters(1) = "'" & FiscalDate & "
Set rS = queryDef.OpenRecordset
Do While Not rS.EOF
'The lines for 1PreviousEWBS
Debug.Print rS.Fields("EWBS") & vbTab & rS.Fields("AWBS") & vbTab & rS.Fields("Total Hours") & vbTab & rS.Fields("Total Cost")
rS.MoveNext
Loop
End Sub
My problem is, I want to recreate the initial "less than" condition, ie
f.[period end date] < [Input Date], and this:
queryDef.Parameters(1) < "'" & FiscalDate & "'"
does not work, it returns an error message of "Invalid Use of Properties"
my question is, how can i show inequal condition when setting parameters for SQL in vba?