Hi Programmers,
Users would like to be able to build their own reports using a combination of unbound listboxes on a report-selection form. Yikes! Currently, users can only select client names, an option group, and starting and ending dates, and then click on one of many cmdbuttons to generate one of many pre-made reports (I included example code below).
I'm not sure how to approach this--not sure how to build a WHERE string from so many listboxes, and not sure how to apply it to one or more reports. How could sorting and grouping be established?
If there are 10 different listboxes, is there a way to rank these in order of importance and in order of grouping for a report? For instance, use textboxes next to each listbox in which a user can type a rank such as "1", "2", "3",..."10", and the report will then group these accordingly?
For instance, in addition to my unbound client listbox named lstClients, there could be potentially 9 other listboxes used:
lstDorms
lstCategory
lstStates
lstShifts
lstInterventions
lstBehaviors
lstReasons
lstManagers
lstStaff
In a report, users may just want to look at the number of interventions that occurred during a certain work shift involving a certain manager.
Or, users may want to output an all-inclusive report grouping data by dormitories, category, state, work shift, intervention, etc.
Here's background info: most of the tables have been set up with many-to-many relationships. For instance, 1 client could show >1 behavior in an intervention, and the intervention could last for >1 shift, and the intervention could involve >1 manager and/or >1 staff person.
THANKS
Here's an example of current report-generating code.
Code:
'Thanks to Browne et al. for the code.
Private Sub cmdViewClientReport_Click()
On Error GoTo Err_cmdViewClientReport_Click
Dim stDocName As String
Dim varItem As Variant
Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strField = "txtDatePart"
Dim strClientList As String
Dim strAnd As String
For Each varItem In lstClients.ItemsSelected
strClientList = strClientList & "," & lstClients.ItemData(varItem)
Next varItem
strClientList = Mid(strClientList, 2)
If Len(strClientList) > 0 Then
strClientList = "ClientID IN (" & strClientList & ")"
End If
If Me.optNames = 1 Then
stDocName = "rptDateDormsandClientsFull"
ElseIf Me.optNames = 2 Then
stDocName = "rptDateDormsandClients"
End If
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then
strWhere = strField & " <= " _
& Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then
strWhere = strField & " >= " _
& Format(Me.txtStartDate, conDateFormat)
Else
strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
If Len(strWhere) > 0 And Len(strClientList) > 0 Then
strAnd = " AND "
End If
strWhere = strWhere & strAnd & strClientList
DoCmd.OpenReport stDocName, acPreview, , strWhere
Exit_cmdViewClientReport_Click:
Exit Sub
Err_cmdViewClientReport_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdViewClientReport_Click
End If
End Sub
Thanks