Hello,
I'm hoping someone here can help me. I have a database which I want to pull reports from. However, new data is added weekly, so I want to filter the data in the report by certain variables. I'm having issues setting the filter up through. I currently have
two textboxes, txtBeginDate and txtEndDate, which I want to use to filter a range of dates. I also currently have a combobox named
cboDMA to choose a Market. I have a button (btnFilterMarket) which is supposed to run the filters and then open the filtered report. My query which has the data I need filtered is named
qryProduction, the form I want to use to filter is named frmFilters, and the report is named
rptProductionNoStores.
I've tried a few things, but I just can't get this thing to work...see below for my code as it currently stands:
Private Sub btnFilterMarket_Click()
Dim strFilter As String
If Not IsNull(Me.cboDMA) Then
strFilter = strFilter & " AND qryPRoduction.DMA = '" & Me.cboDMA & "'"
End If
If txtBeginDate <> "" And txtEndDate <> "" Then
strFilter = strFilter & " AND txtBeginDate >= #" & Format(CDate(Me.txtBeginDate), "mm/dd/yyyy") & "# AND txtEndDate <= #" & Format(CDate(Me.txtEndDate), "mm/dd/yyyy") & "#"
End If
If strFilter = "" Then
Me.Filter = ""
Me.FilterOn = False
Else
Me.Filter = Mid(strFilter, 5)
Me.FilterOn = True
End If
DoCmd.OpenReport "rptProductionNoStores", acViewPreview, "qryPRoduction"
End Sub
Thank you!