G
Guest
I have a form that has two list fields (namelst and sourcelst) and one button
group (statusfra) for users to choose from in order to customize a report
(trkng_rpt). I want the user to be able to choose any number of names and or
any number of sources and whether the request is open (no date in the status
field of the report), closed (date in the status field) or both. The name
field is an unbound text box on the report that combines the [Last Name],
[First Name], and [Middle Initial] into one text string separated by commas.
The Source and Status are both taken from form controls. Also I would like
to be able to sort the query choices but have not got that far yet because I
cannot seem to get the first part to work right. Here is my code for the
filter buttons:
Private Sub filter_cmd_Click()
Dim varItem As Variant
Dim strName As String
Dim strSource As String
Dim strStatus As String
Dim strFilter as String
' Check if the report is open
If SysCmd(acSysCmdgetObjectState, acReport, "trkng_rpt") <>
acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Criteria String from namelst listbox
For Each varItem In Me.namelst.ItemsSelected
strName = strName & ",'" & Me.namelst.ItemData(varItem)
& "'"
Next varItem
If Len(strName) = 0
strName = "Like '*'"
Else
strName = Right(strName, Len(strName) -1)
strName = "IN(" & strName & ")"
End If
' Criteria String from sourcelst listbox
For Each varItem In Me.sourcelst.ItemsSelected
strSource = strSource & ",'" & Me.sourcelst.ItemData(varItem)
& "'"
Next varItem
If Len(strSource) = 0 Then
strSource = "Like '*'"
Else
strSource = Right(strSource, Len(strSource) -1)
strSource = "IN(" & strSource & ")"
End If
' Criteria String from statusfra frame
Select Case Me.statusfra.Value
Case 1
strStatus = "Is Null"
Case 2
strStatus = "Is Not Null"
Case 3
strStatus = "Like '*'"
End Select
' Filter string
strFilter = "[Name] " & strName &
" AND [Source] " & strSource & _
" AND [Status] " & strStatus
' Apply Filter
With Reports![trkng_rpt]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Private Sub remove_fltr_Click()
On Error Resume Next
' Remove Filter
Reports![trkng_rpt].FilterOn = False
End Sub
I can query on any number of sources so that works fine. I can also query
on either open or closed status but when I choose both it seems to remove the
filter because I see everything. The remove filter button works fine.
However, if I choose any name(s) from the list the report is blank. I have
been trying to work this for days now. I separated the name part of the code
from the source and status and made one for just names and one for both
source and status. Both worked fine. It is only when I combine the two that
the name never works. I am thinking that it is becase it is an unbound text
box but I would really like to use the lastname, firstname, mi format used in
the list box. Any and all help will be extremely appreciated. Thanks.
group (statusfra) for users to choose from in order to customize a report
(trkng_rpt). I want the user to be able to choose any number of names and or
any number of sources and whether the request is open (no date in the status
field of the report), closed (date in the status field) or both. The name
field is an unbound text box on the report that combines the [Last Name],
[First Name], and [Middle Initial] into one text string separated by commas.
The Source and Status are both taken from form controls. Also I would like
to be able to sort the query choices but have not got that far yet because I
cannot seem to get the first part to work right. Here is my code for the
filter buttons:
Private Sub filter_cmd_Click()
Dim varItem As Variant
Dim strName As String
Dim strSource As String
Dim strStatus As String
Dim strFilter as String
' Check if the report is open
If SysCmd(acSysCmdgetObjectState, acReport, "trkng_rpt") <>
acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Criteria String from namelst listbox
For Each varItem In Me.namelst.ItemsSelected
strName = strName & ",'" & Me.namelst.ItemData(varItem)
& "'"
Next varItem
If Len(strName) = 0
strName = "Like '*'"
Else
strName = Right(strName, Len(strName) -1)
strName = "IN(" & strName & ")"
End If
' Criteria String from sourcelst listbox
For Each varItem In Me.sourcelst.ItemsSelected
strSource = strSource & ",'" & Me.sourcelst.ItemData(varItem)
& "'"
Next varItem
If Len(strSource) = 0 Then
strSource = "Like '*'"
Else
strSource = Right(strSource, Len(strSource) -1)
strSource = "IN(" & strSource & ")"
End If
' Criteria String from statusfra frame
Select Case Me.statusfra.Value
Case 1
strStatus = "Is Null"
Case 2
strStatus = "Is Not Null"
Case 3
strStatus = "Like '*'"
End Select
' Filter string
strFilter = "[Name] " & strName &
" AND [Source] " & strSource & _
" AND [Status] " & strStatus
' Apply Filter
With Reports![trkng_rpt]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Private Sub remove_fltr_Click()
On Error Resume Next
' Remove Filter
Reports![trkng_rpt].FilterOn = False
End Sub
I can query on any number of sources so that works fine. I can also query
on either open or closed status but when I choose both it seems to remove the
filter because I see everything. The remove filter button works fine.
However, if I choose any name(s) from the list the report is blank. I have
been trying to work this for days now. I separated the name part of the code
from the source and status and made one for just names and one for both
source and status. Both worked fine. It is only when I combine the two that
the name never works. I am thinking that it is becase it is an unbound text
box but I would really like to use the lastname, firstname, mi format used in
the list box. Any and all help will be extremely appreciated. Thanks.