View Full Version : Report filter problem (access 2007)


roid
09-03-2008, 04:38 PM
While browsing i found another code on your site that i modified a little and it works just fine except when i select both drown fields with the start and end date it won't filter one of the dropdown fields. Is there something i missed in modifying the code?

Private Sub cmdApplyFilter_Click()
Dim strFilter As String
Dim blnFilterOn As Boolean
Dim strCriteria As String

strCriteria = "Criteria: "

If Nz(Me.cboVerzekering, vbNullString) <> vbNullString Then
strFilter = " AND [Verzekering] = '" & Me.cboVerzekering & "'"
strCriteria = strCriteria & "Verzekering = " & cboVerzekering
End If

If Nz(Me.txtStartDate, vbNullString) <> vbNullString And Nz(Me.txtEndDate, vbNullString) <> vbNullString Then
If Me.txtStartDate > Me.txtEndDate Then
MsgBox "Start Datum kan niet groter zijn dan Eind Datum", vbInformation
Exit Sub
End If
End If
If Nz(Me.txtStartDate, vbNullString) <> vbNullString Then
strFilter = strFilter & " AND [Datum verwijzing] >= #" & Me.txtStartDate & "#"
strCriteria = strCriteria & vbCrLf & "Begin Date: " & Me.txtStartDate
End If

If Nz(Me.txtEndDate, vbNullString) <> vbNullString Then
strFilter = strFilter & " AND [Datum verwijzing] <= #" & Me.txtEndDate & "#"
strCriteria = strCriteria & vbCrLf & "End Date: " & Me.txtEndDate
End If


If strFilter <> vbNullString Then
strFilter = Mid(strFilter, 6)
Me.txtCriteria = strCriteria
Reports("PatientenVerwijzing").Filter = strFilter
Reports("PatientenVerwijzing").FilterOn = True
Else
MsgBox "Vul aub wat informatie in!", vbInformation
End If


End Sub

Also in the "On Open" property i have this code to open the report to filter:
On opening the form detailed above i have the "On open" property filled in with this:
Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenReport "PatientenVerwijzing", acPreview
End Sub

So when the form opens the report is immediately opened to.
The problem what i have is that i must be able to filter on 4 fields. 2 of these or dropdowns and the other 2 are start/end date fields. The problem is that all 4 fields must work together when filtering the report.
Eg: show me all the Johns living in Ohio between 01/08/2000 and 01/09/2008. When i filter with the code i submitted earlier i it still shows me one of the result in the dropdown that i didn't ask (eg Johns in Texas). Somewhere the filtering goes wrong and with my basic access experience i am pulling hair out !!!

So i someone can help me please ....... :(

llkhoutx
09-04-2008, 05:24 AM
strFilter =""
strCriteria = "Criteria: "

If Nz(Me.cboVerzekering, vbNullString) <> vbNullString Then
strFilter = "[Verzekering] = '" & Me.cboVerzekering & "'"
strCriteria = strCriteria & "Verzekering = " & cboVerzekering
End If

If Nz(Me.txtStartDate, vbNullString) <> vbNullString And Nz(Me.txtEndDate, vbNullString) <> vbNullString Then
If Me.txtStartDate > Me.txtEndDate Then
MsgBox "Start Datum kan niet groter zijn dan Eind Datum", vbInformation
Reports("PatientenVerwijzing").FilterOn = False
Exit Sub
End If
End If
If Nz(Me.txtStartDate, vbNullString) <> vbNullString Then
strFilter = strFilter & " AND [Datum verwijzing] >= #" & Me.txtStartDate & "#"
strCriteria = strCriteria & vbCrLf & "Begin Date: " & Me.txtStartDate
End If

If Nz(Me.txtEndDate, vbNullString) <> vbNullString Then
strFilter = strFilter & " AND [Datum verwijzing] <= #" & Me.txtEndDate & "#"
strCriteria = strCriteria & vbCrLf & "End Date: " & Me.txtEndDate
End If


If strFilter <> vbNullString Then
'strFilter = Mid(strFilter, 6)
Me.txtCriteria = strCriteria
Reports("PatientenVerwijzing").Filter = strFilter
Reports("PatientenVerwijzing").FilterOn = True
Else
Reports("PatientenVerwijzing").FilterOn = False
MsgBox "Vul aub wat informatie in!", vbInformation
End If