A
Ann
I am using Access 2002. I'm not a programmer but can alter code I find. I
have the following code listed below on a button to filter the data depending
on what data the user picks from the combo boxes.
The problem I'm having is sometimes there isn't any data in a field so the
Like '*' keeps me from getting the correct result. I need to somehow tell it
that any field that was not chosen by picking from the combo box could be
Like '*' or it could be null. Thanks in advance for the help.
Private Sub cmdApplyFilter_Click()
'Check if report is closed.
'If the report is closed open the report after clicking the OK button.
If SysCmd(acSysCmdGetObjectState, acReport, "rptClassesFilter") <> _
acObjStateOpen Then
MsgBox "You must open the report first."
Dim stDocName As String
stDocName = "rptClassesFilter"
DoCmd.OpenReport stDocName, acPreview
Exit Sub
End If
'Declare variables
Dim strBrochureType As String
Dim strBuildingLocation As String
Dim strPrimaryCompetency As String
Dim strSecondaryCompetency As String
Dim strSupplementalCompetency As String
Dim strDepartmentType As String
Dim strInstructorName As String
Dim strTrainingRoom As String
Dim strWorkLifeType As String
Dim strFilter As String
'Brochure Type
If IsNull(Me.cboBrochure.Value) Then
strBrochureType = "Like '*'"
Else
strBrochureType = "='" & Me.cboBrochure.Value & "'"
End If
'Building Location
If IsNull(Me.cboBuildingLocation.Value) Then
strBuildingLocation = "Like '*'"
Else
strBuildingLocation = "='" & Me.cboBuildingLocation.Value & "'"
End If
'Primary Competency
If IsNull(Me.cboPrimaryCompetency.Value) Then
strPrimaryCompetency = "Like '*'"
Else
strPrimaryCompetency = "='" & Me.cboPrimaryCompetency.Value & "'"
End If
'Secondary Competency
If IsNull(Me.cboSecondaryCompetency.Value) Then
strSecondaryCompetency = "Like '*'"
Else
strSecondaryCompetency = "='" & Me.cboSecondaryCompetency.Value & "'"
End If
'Supplemental Competency
If IsNull(Me.cboSupplementalCompetency.Value) Then
strSupplementalCompetency = "Like '*'"
Else
strSupplementalCompetency = "='" &
Me.cboSupplementalCompetency.Value & "'"
End If
'Department
If IsNull(Me.cboDepartment.Value) Then
strDepartmentType = "Like '*'"
Else
strDepartmentType = "='" & Me.cboDepartment.Value & "'"
End If
'Instructor Name
If IsNull(Me.cboInstructors.Value) Then
strInstructorName = "Like '*'"
Else
strInstructorName = "='" & Me.cboInstructors.Value & "'"
End If
'Training Room
If IsNull(Me.cboTrainingRoom.Value) Then
strTrainingRoom = "Like '*'"
Else
strTrainingRoom = "='" & Me.cboTrainingRoom.Value & "'"
End If
'Work Life
If IsNull(Me.cboWorkLife.Value) Then
strWorkLifeType = "Like '*'"
Else
strWorkLifeType = "='" & Me.cboWorkLife.Value & "'"
End If
'Filter the string for each declared variable
strFilter = "[txtBrochureType] " & strBrochureType & _
" AND [txtBuildingLocation] " & strBuildingLocation & _
" AND [txtPrimaryCompetency] " & strPrimaryCompetency & _
" AND [txtSecondaryCompetency] " & strSecondaryCompetency & _
" AND [txtSupplementalCompetency] " & strSupplementalCompetency & _
" AND [txtDepartmentType] " & strDepartmentType & _
" AND [lngInstructorID] " & strInstructorName & _
" AND [txtTrainingRoom] " & strTrainingRoom & _
" AND [txtWorkLifeType] " & strWorkLifeType
'Filter Property is turned on
With Reports![rptClassesFilter]
.Filter = strFilter
.FilterOn = True
End With
End Sub
have the following code listed below on a button to filter the data depending
on what data the user picks from the combo boxes.
The problem I'm having is sometimes there isn't any data in a field so the
Like '*' keeps me from getting the correct result. I need to somehow tell it
that any field that was not chosen by picking from the combo box could be
Like '*' or it could be null. Thanks in advance for the help.
Private Sub cmdApplyFilter_Click()
'Check if report is closed.
'If the report is closed open the report after clicking the OK button.
If SysCmd(acSysCmdGetObjectState, acReport, "rptClassesFilter") <> _
acObjStateOpen Then
MsgBox "You must open the report first."
Dim stDocName As String
stDocName = "rptClassesFilter"
DoCmd.OpenReport stDocName, acPreview
Exit Sub
End If
'Declare variables
Dim strBrochureType As String
Dim strBuildingLocation As String
Dim strPrimaryCompetency As String
Dim strSecondaryCompetency As String
Dim strSupplementalCompetency As String
Dim strDepartmentType As String
Dim strInstructorName As String
Dim strTrainingRoom As String
Dim strWorkLifeType As String
Dim strFilter As String
'Brochure Type
If IsNull(Me.cboBrochure.Value) Then
strBrochureType = "Like '*'"
Else
strBrochureType = "='" & Me.cboBrochure.Value & "'"
End If
'Building Location
If IsNull(Me.cboBuildingLocation.Value) Then
strBuildingLocation = "Like '*'"
Else
strBuildingLocation = "='" & Me.cboBuildingLocation.Value & "'"
End If
'Primary Competency
If IsNull(Me.cboPrimaryCompetency.Value) Then
strPrimaryCompetency = "Like '*'"
Else
strPrimaryCompetency = "='" & Me.cboPrimaryCompetency.Value & "'"
End If
'Secondary Competency
If IsNull(Me.cboSecondaryCompetency.Value) Then
strSecondaryCompetency = "Like '*'"
Else
strSecondaryCompetency = "='" & Me.cboSecondaryCompetency.Value & "'"
End If
'Supplemental Competency
If IsNull(Me.cboSupplementalCompetency.Value) Then
strSupplementalCompetency = "Like '*'"
Else
strSupplementalCompetency = "='" &
Me.cboSupplementalCompetency.Value & "'"
End If
'Department
If IsNull(Me.cboDepartment.Value) Then
strDepartmentType = "Like '*'"
Else
strDepartmentType = "='" & Me.cboDepartment.Value & "'"
End If
'Instructor Name
If IsNull(Me.cboInstructors.Value) Then
strInstructorName = "Like '*'"
Else
strInstructorName = "='" & Me.cboInstructors.Value & "'"
End If
'Training Room
If IsNull(Me.cboTrainingRoom.Value) Then
strTrainingRoom = "Like '*'"
Else
strTrainingRoom = "='" & Me.cboTrainingRoom.Value & "'"
End If
'Work Life
If IsNull(Me.cboWorkLife.Value) Then
strWorkLifeType = "Like '*'"
Else
strWorkLifeType = "='" & Me.cboWorkLife.Value & "'"
End If
'Filter the string for each declared variable
strFilter = "[txtBrochureType] " & strBrochureType & _
" AND [txtBuildingLocation] " & strBuildingLocation & _
" AND [txtPrimaryCompetency] " & strPrimaryCompetency & _
" AND [txtSecondaryCompetency] " & strSecondaryCompetency & _
" AND [txtSupplementalCompetency] " & strSupplementalCompetency & _
" AND [txtDepartmentType] " & strDepartmentType & _
" AND [lngInstructorID] " & strInstructorName & _
" AND [txtTrainingRoom] " & strTrainingRoom & _
" AND [txtWorkLifeType] " & strWorkLifeType
'Filter Property is turned on
With Reports![rptClassesFilter]
.Filter = strFilter
.FilterOn = True
End With
End Sub