I need the following report to open with date parameters.
I have the following code, but it doesn't quite work.
When an item is chosen from Modl (a list box) a box pops up asking for LowPop, then another for Start Year and then another for End Year.
Those last two aren't doing what they should. They should restrice the [Date] field to between the years entered as start and end.
I would like to put it in the "OpenReport" line, but don't think that's going to work.
Any help would be appreciated.
Code:
Private Sub Command27_Click()
Dim varItm As Variant
Dim ModelWhere As String
Dim strQuery
Dim LowPop As String
Dim SDate As Date
Dim EDate As Date
Dim qdf As DAO.QueryDef
If SysCmd(acSysCmdGetObjectState, acQuery, "CompactSUMQry") = acObjStateOpen Then
DoCmd.Close acQuery, "CompactSUMQry"
End If
Set qdf = CurrentDb.QueryDefs("CompactSUMQry")
LowPop = InputBox("Please Enter Minimum Population", "Population")
SDate = InputBox("Enter Start Year")
EDate = InputBox("Enter End Year")
strQuery = "SELECT * FROM dbo_BAMtbl WHERE ((dbo_BAMtbl.Pop)>=" & LowPop & " AND "
For Each varItm In Me.Modl.ItemsSelected
If ModelWhere = "" Then
ModelWhere = "[dbo_BAMtbl].[Model]=" & _
Chr(34) & Me.Modl.Column(0, varItm) & Chr(34)
Else
ModelWhere = ModelWhere & " OR [dbo_BAMtbl].[Model]=" & _
Chr(34) & Me.Modl.Column(0, varItm) & Chr(34)
End If
Next varItm
strQuery = strQuery & "(" & ModelWhere & "));"
qdf.SQL = strQuery
DoCmd.OpenReport "SUMrptCmpct", acViewPreview, , WhereCondition:="(" & [Date] & " >=" & SDate & " And " & "<= EDate&"")"
Set qdf = Nothing
End Sub