It depends where you are opening the report from. I would suggest that if you are using a command button on a form you add a combobox (cboYear) above it with a list of Years (You could just design a lookup table or set a query to get the year field from the query grouped on year field).
Ask the user to select a year before running the report and in the On Click event of the button (cmdPrint) put the following code.
-
Private Sub cmdPrint_OnClick()
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
If IsNull(Me.cboYear) Then
-
Msgbox "You must select a year", vbOkOnly
-
Exit Sub
-
Else
-
stDocName = "Name of Crosstab Query Report"
-
stLinkCriteria = "[Year]=" & Me.cboYear
-
DoCmd.OpenReport stDocName, , , stLinkCriteria
-
End Sub
-
Put a textbox control on the Report next to the Header Label and set the source to
=[Forms]![FormName]![cboYear]
Quote:
Originally Posted by jilppe
I was able to solve the problem with the report and the form acting as a filter. The only question I still have is the one below
Also I have a report that uses a crosstab query called bodycrosstab. This cross tab counts the number of incidents for each body part for each month. The report and query are working fine but I need a way that each time the report is run it asks which year should be used (and then filters the data in the report for that year. This would also need to be made availabile in the header of the report so if I selected 2005 then the header of the report would be Body Parts 2005.