I ned to create a form that asks the user which reports they want to preview/print. I see it as a set of tick boxes with one saying all, then a print button. Im not really sure though, can someone offer some advise or maybe an example?
Create a listbox on a form and call it LstReports. In the Multi Select properties select 'simple'. In the Row Source place the following query...
SELECT MSysObjects.Name
FROM MSysObjects
WHERE (((Left([Name],1))<>"~") AND ((MSysObjects.Type)=-32764))
ORDER BY MSysObjects.Name;
This will list all reports in your db.
Create a 'Select All' and a 'Deselect All' button on your form. Put this code in the OnClick event of the 'Select All' button....
Code:
Dim i As Integer
For i = 0 To LstReports.ListCount - 1
Me.LstReports.Selected(i) = True
Next i
and this code in the OnClick event of the 'Deselect All' button....
Code:
Dim i As Integer
For i = 0 To LstReports.ListCount - 1
Me.LstReports.Selected(i) = False
Next i
Finally create a 'Print Prieview' button on the form and put this code in the OnClick event....
Code:
Dim vntIndex As Variant
Dim strValue As String
For Each vntIndex In LstReports.ItemsSelected
strValue = LstReports.ItemData(vntIndex)
DoCmd.OpenReport strValue, acViewPreview
Next
Just one more thing, at present the reports are sorting in to alpahabetical order. I know I can remove the sort command from the query but is there a way that I can make them be in an order that I want?
You could create a table with two columns. Column one ID number (not autonumber), column two all your reports, then base the listbox query on that table and order by number.