Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to automate event programming? 2

Status
Not open for further replies.

GSMike

Programmer
Feb 7, 2001
143
US
Do you know, is it possible to automate event programming for a report? I mean, I have this report that is created, formatted and destroyed, all through code. Every time a user runs the report, it is created all over again, printed and destroyed.
I need an "on close" event for the report, and I don't know how to put code in a report using code.
Any suggestions?
This is Access 97, by the way.
Thank you for your help.
Mike Kemp
s-)
 
While you're creating your report and it's open in design view, pass it to the following procedure:
Code:
Public Sub BuildReportModule(Report As Report)
    Dim mdl As Module
    
    On Error GoTo ErrorHandler
    Set mdl = Report.Module
    mdl.InsertText _
        "Private Sub Report_Close" & vbCrLf & _
        "    Me!GrandTotal = CLng(Me!Total1) + CLng(Me!Total2)" & vbCrLf & _
        "End Sub" & vbCrLf
ErrorExit:
    Exit Sub
ErrorHandler:
    Select Case Err.Number
        Case 0 ' TODO: Replace with expected error number
    End Select
    ' Unknown error - re-raise to VBA default error handler
    Beep
    MsgBox "Runtime error " & Err.Number & ": " & Err.Description, vbExclamation
    Err.Raise Err.Number
End Sub
Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top