James:
Below is some sample code that shows one way to accomplish this. You can
only add code to a report module when the report is in design view, so you
still have to open the report, but you can automate the process and hide the
design view. You will need to determine how to identify your new reports so
that only those reports will be updated. The Module class also contains an
AddFromFile method to add the script from a text file, as well as other
methods for inserting or deleting text. See Access Help for more
information.
Function AddOnCloseEvent()
Dim sProc As String
Dim rpt As AccessObject
sProc = "Private Sub Report_Close()" & vbCrLf & "IF 1=1 Then " & vbCrLf
& vbTab & _
"Debug.Print " & """" & "True!" & """" & vbCrLf & "Else " &
vbCrLf & vbTab & _
"Debug.Print " & """" & "False!" & """" & vbCrLf & "End If" &
vbCrLf & "End Sub"
For Each rpt In CurrentProject.AllReports
If rpt.Name = "MyReport" Then
DoCmd.OpenReport rpt.Name, acViewDesign, , , acHidden
Modules("Report_" & rpt.Name).AddFromString sProc
Reports(rpt.Name).OnClose = "[Event Procedure]"
DoCmd.Close acReport, rpt.Name, acSaveYes
End If
Next rpt
End Function
--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
This response is supplied "as is" without any representations or warranties.
I have a Access Database that allows importing new reports.
Is their a way to add code to the OnClose Event of the new reports
automatically.
I would like to loop through the report objects and add code to the onclose
event of the new reports without going into design view.