manderson_zim
New member
- Local time
- Today, 18:51
- Joined
- Mar 31, 2011
- Messages
- 7
I am very new to access 2007 and struggling with the code for a form named frmSearch that I am using to filter a report named rptBibleStudies.
There are two frames on the form which each filter one of the following fields: [Book] and [Chapter]. If the field is left blank in the frmSearch, then I want the report to display all records for that field. It is working well except for one thing; some fields are left blank during data entry and these records are not being returned after filtering. For example: if during data entry the [Chapter] field is left blank and the user does not enter a value to filter [Chapter] by in the frmSearch, then this record will not be included in the rptBibleStudies.
I know it has something to do with the expression Like and Null fields, but I don't know how to fix it. Here is part of the code used:
Private Sub cmdFilter_Click()
Dim strBook As String
Dim strChapter As String
Dim strFilter As String
' Build criteria string for searching by Book
If IsNull(Me.cbobook.Value) Then
strBook = "Like '*'"
Else
strBook = "='" & Me.cbobook.Value & "'"
End If
' Build criteria string for searching by Chapter
If IsNull(Me.txtChapter.Value) Then
strChpater = "Like '*'"
Else
strChapter = "Like '*" & Me.txtChapter.Value & "*'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[Book]" & strBook & "AND [Chapter]" & strChapter _
' Apply the filter and switch it on
With Reports![rptBibleStudies]
.Filter = strFilter
.FilterOn = True
End With
[FONT="]End Sub[/FONT]
There are two frames on the form which each filter one of the following fields: [Book] and [Chapter]. If the field is left blank in the frmSearch, then I want the report to display all records for that field. It is working well except for one thing; some fields are left blank during data entry and these records are not being returned after filtering. For example: if during data entry the [Chapter] field is left blank and the user does not enter a value to filter [Chapter] by in the frmSearch, then this record will not be included in the rptBibleStudies.
I know it has something to do with the expression Like and Null fields, but I don't know how to fix it. Here is part of the code used:
Private Sub cmdFilter_Click()
Dim strBook As String
Dim strChapter As String
Dim strFilter As String
' Build criteria string for searching by Book
If IsNull(Me.cbobook.Value) Then
strBook = "Like '*'"
Else
strBook = "='" & Me.cbobook.Value & "'"
End If
' Build criteria string for searching by Chapter
If IsNull(Me.txtChapter.Value) Then
strChpater = "Like '*'"
Else
strChapter = "Like '*" & Me.txtChapter.Value & "*'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[Book]" & strBook & "AND [Chapter]" & strChapter _
' Apply the filter and switch it on
With Reports![rptBibleStudies]
.Filter = strFilter
.FilterOn = True
End With
[FONT="]End Sub[/FONT]