Hi, Jonathan.
To enable your users to create new reports with the Report Wizard on their
own (and this freedom will cause you no end of headaches, I assure you),
here is some sample code I posted recently that uses a table named "TableA"
as the basis for a new report. The new report is renamed to another name,
and the title caption of the report in the header is also renamed. Of
course, the acwzmain.MDE library reference is required.
' ***** Start of code *****
'==================================================
' This procedure requires the acwzmain.MDE library reference.
' ASSUMPTIONS:
' 1. A report named "TableA" has already been saved.
' 2. No report named "TableA1" has yet been saved.
'==================================================
Public Sub createReport_Click( )
On Error GoTo ErrHandler
Dim rpt As Report
Dim ctrl As Control
Dim sTblName As String
sTblName = "TableA"
Call acwzmain.frui_entry(sTblName, acReport)
DoCmd.Close acReport, sTblName & "1", acSaveYes
DoCmd.Rename "rptMyReport", acReport, sTblName & "1"
DoCmd.OpenReport "rptMyReport", acViewDesign
Set rpt = Reports("rptMyReport")
For Each ctrl In rpt.Section(acHeader).Controls
'-------------------------------------------
' Find 1st label & replace the caption.
'-------------------------------------------
If (ctrl.ControlType = acLabel) Then
rpt.Section(acHeader).Controls(ctrl.Name).Caption = "MyTitle"
Exit For ' Stop looking.
End If
Next ctrl
DoCmd.Close acReport, rpt.Name, acSaveYes
CleanUp:
Set ctrl = Nothing
Set rpt = Nothing
Exit Sub
ErrHandler:
MsgBox "Error in createReport_Click( ) in RptFunctions." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp
End Sub ' createReport_Click( )
' ***** End of code *****
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)