G
Guest
I need serious help. I have been trying to make this report filter for what
seems like forever.
I have a huge query, since I couldn't figure out how to filter both a form
and subform and read it wasn't a great way to go. The query is all the
information for my employees and all the information on training they have
taken.
I have two different reports that need to be opened. One from each view
point.
1. Employee and all the classes they took (EmpRegReport)
2. Class and all the Employees that took it (CourseRegReport)
I have a form frmTracker that has all the options I need on it. However
there are a lot of options. The first Option group decides which report will
open and filter.
The second option group is connected with a multi select list box. To
choose if the report will be filtered by Employee (then select which
employees), Department (then select which departments) and so on.
The third list box is the status of the class the employee took. Whether it
was completed, incomplete, missed.....
There is also a date range I need to enter but I haven't gotten that far
down the form yet.
I can make the first two work fine but as soon as I try to filter on with
the status, I get errors or type mismatch or it just won't accept the filter.
Any information would be GREATLY appreciated. Or if there is an
easier/better way to get what I'm trying to do, I would love to hear it.
Thanks so much.
Sample of code (there are 8 cases and basically they look the same, save the
data pulled...name, department, shift....)
Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click
Dim strDoc As String
Dim varItem As Variant
Dim strCriteria As String
Dim strStatus As String
Dim strFilter As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryRegistration")
'Build Criteria for View Info Frame
Select Case Me.ViewInfoFrame.Value
Case 1
strDoc = "RegistrationReport"
Case 2
strDoc = "CourseMainRprt"
End Select
'Build Criteria for Frame80
Select Case Me!Frame80
Case 1
For Each varItem In Me!FilterList.ItemsSelected
strCriteria = strCriteria & "'" &
Me!FilterList.ItemData(varItem) & "',"
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "Please Make a Selection" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Left(strCriteria, Len(strCriteria) - 1)
strCriteria = "SELECT * FROM qryRegQuery WHERE
qryRegQuery.EmpName IN(" & strCriteria & ") ORDER BY qryRegQuery.EmpName;"
End Select
With Me.lstStatus
For Each varItem In Me!lstStatus.ItemsSelected
strStatus = strStatus & "'" & Me!lstStatus.ItemData(varItem) &
"',"
Next varItem
If Len(strStatus) = 0 Then
MsgBox "Please Make a Selection" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strStatus = Left(strStatus, Len(strStatus) - 1)
strStatus = "SELECT * FROM qryRegQuery WHERE qryRegQuery.Status
IN(" & strStatus & ");"
End With
qdf.SQL = " & strCriteria & " And " & strStatus & "
DoCmd.OpenForm strDoc, acPreview, , qdf.SQL
Set db = Nothing
Set qdf = Nothing
seems like forever.
I have a huge query, since I couldn't figure out how to filter both a form
and subform and read it wasn't a great way to go. The query is all the
information for my employees and all the information on training they have
taken.
I have two different reports that need to be opened. One from each view
point.
1. Employee and all the classes they took (EmpRegReport)
2. Class and all the Employees that took it (CourseRegReport)
I have a form frmTracker that has all the options I need on it. However
there are a lot of options. The first Option group decides which report will
open and filter.
The second option group is connected with a multi select list box. To
choose if the report will be filtered by Employee (then select which
employees), Department (then select which departments) and so on.
The third list box is the status of the class the employee took. Whether it
was completed, incomplete, missed.....
There is also a date range I need to enter but I haven't gotten that far
down the form yet.
I can make the first two work fine but as soon as I try to filter on with
the status, I get errors or type mismatch or it just won't accept the filter.
Any information would be GREATLY appreciated. Or if there is an
easier/better way to get what I'm trying to do, I would love to hear it.
Thanks so much.
Sample of code (there are 8 cases and basically they look the same, save the
data pulled...name, department, shift....)
Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click
Dim strDoc As String
Dim varItem As Variant
Dim strCriteria As String
Dim strStatus As String
Dim strFilter As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryRegistration")
'Build Criteria for View Info Frame
Select Case Me.ViewInfoFrame.Value
Case 1
strDoc = "RegistrationReport"
Case 2
strDoc = "CourseMainRprt"
End Select
'Build Criteria for Frame80
Select Case Me!Frame80
Case 1
For Each varItem In Me!FilterList.ItemsSelected
strCriteria = strCriteria & "'" &
Me!FilterList.ItemData(varItem) & "',"
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "Please Make a Selection" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Left(strCriteria, Len(strCriteria) - 1)
strCriteria = "SELECT * FROM qryRegQuery WHERE
qryRegQuery.EmpName IN(" & strCriteria & ") ORDER BY qryRegQuery.EmpName;"
End Select
With Me.lstStatus
For Each varItem In Me!lstStatus.ItemsSelected
strStatus = strStatus & "'" & Me!lstStatus.ItemData(varItem) &
"',"
Next varItem
If Len(strStatus) = 0 Then
MsgBox "Please Make a Selection" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strStatus = Left(strStatus, Len(strStatus) - 1)
strStatus = "SELECT * FROM qryRegQuery WHERE qryRegQuery.Status
IN(" & strStatus & ");"
End With
qdf.SQL = " & strCriteria & " And " & strStatus & "
DoCmd.OpenForm strDoc, acPreview, , qdf.SQL
Set db = Nothing
Set qdf = Nothing