insert code into an object using code !

Happy YN

Registered User.
Local time
Today, 22:25
Joined
Jan 27, 2002
Messages
425
I am creating a report using code, however I want the report to have code in its on format event. How can I write code which will insert itself into this event on the report once it is created?
Alternatively could I have a piece of code that is automatically inserted into every report created? e.g by having a standard report template
Thanks
 
To insert the code on the OnFormat event of a report: right-click the appropriate header section of the report in design view and then select properties icon from the menu, then select the OnFormat event which will build the call to that event. Input your code there.

You can call a function from the OnFormat event of every report, by inserting "=YourfunctionName()" without the quotation marks in each report. Build that public function in a module before modifying the OnFormat property.
 
You have not understood my question!
I am building the report using vba It gets built on the fly The user cannot right click etc!!!but I want to be able to put code into the report which will execute itself when the report is opened
Thanks!
 
If you're building your report on the fly, put the wanted code in a class function, then "on-the-fly" modify the appropriate report section OnFormat property to call the function., i.e.





Reports!YourReportName.Section(i).OnFormat = "=YourFunctionName"

where i is the appropriate report section number
 
Thanks, this is the code I wish to insert

Private m_RowCount As Long

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
m_RowCount = m_RowCount + 1
If m_RowCount / 2 = CLng(m_RowCount / 2) Then
Me.Detail.BackColor = 15263976 'Change value to the color you desire
Else
Me.Detail.BackColor = 14811135 'Change value to the color you desire
End If
End Sub

So how would I do this?
Thanks
 

Users who are viewing this thread

Back
Top Bottom