Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

OnClose Event New Report

Discussion in 'Information Technology' started by James, Nov 1, 2005.

  1. James

    James
    Expand Collapse
    Guest

    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.
     
  2. Loading...


  3. David Lloyd

    David Lloyd
    Expand Collapse
    Guest

    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.


    "James" <James@discussions.microsoft.com> wrote in message
    news:3A5CD161-FC6B-4A57-B4DC-1BC2401955E6@microsoft.com...
    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.
     

Share This Page