'预览按钮 Private Sub btnPreview_Click() Dim rpt As New ActiveReport1 Set rpt.Grid = datagrid1 rpt.Show End Sub'activereport设计器里的内容 Option ExplicitPrivate m_grid As dataGrid Private bDone As BooleanProperty Set Grid(grd As datagrid) Dim col As Column Dim ctl As Object Dim iLeft As Integer Set m_grid = grd
Detail.Height = grd.RowHeight
With m_grid For Each col In .Columns Set ctl = Detail.Controls.Add("DDActiveReports2.Field") ctl.Left = iLeft ctl.Top = 0 ctl.Height = Detail.Height ctl.Width = col.Width ctl.Tag = col.ColIndex ctl.Font.Name = m_grid.Font.Name ctl.Font.Size = m_grid.Font.Size Fields.Add ctl.Name ctl.DataField = ctl.Name
ctl.Font.Name = m_grid.HeadFont.Name ctl.Font.Size = m_grid.HeadFont.Size iLeft = iLeft + col.Width + 144 If iLeft > PrintWidth Then PrintWidth = iLeft Next End With End PropertyPrivate Sub ActiveReport_FetchData(eof As Boolean) Static lRow As Long Dim ctl As Object
If m_grid Is Nothing Then Exit Sub On Error GoTo ehFetchData
m_grid.Row = lRow For Each ctl In Detail.Controls Fields(ctl.Name).Value = m_grid.Columns(ctl.Tag) Next lRow = lRow + 1 eof = False
exFetchData: Exit Sub
ehFetchData: Err.Clear Resume exFetchData End SubPrivate Sub ActiveReport_ReportEnd() If m_grid Is Nothing Then Exit Sub m_grid.Visible = True End SubPrivate Sub ActiveReport_ReportStart() If m_grid Is Nothing Then Exit Sub m_grid.Visible = False End Sub
为什么我按上面的做了,可是会出现如下错误, Error 5800 : Source: Report , Event: OnError , Line number: 0 Description:Fatal Exception during script excution.Error 5000 : Error in processing report. [ Extended Info: CP internal=10]
Private Sub btnPreview_Click()
Dim rpt As New ActiveReport1
Set rpt.Grid = datagrid1
rpt.Show
End Sub'activereport设计器里的内容
Option ExplicitPrivate m_grid As dataGrid
Private bDone As BooleanProperty Set Grid(grd As datagrid)
Dim col As Column
Dim ctl As Object
Dim iLeft As Integer Set m_grid = grd
Detail.Height = grd.RowHeight
With m_grid
For Each col In .Columns
Set ctl = Detail.Controls.Add("DDActiveReports2.Field")
ctl.Left = iLeft
ctl.Top = 0
ctl.Height = Detail.Height
ctl.Width = col.Width
ctl.Tag = col.ColIndex
ctl.Font.Name = m_grid.Font.Name
ctl.Font.Size = m_grid.Font.Size
Fields.Add ctl.Name
ctl.DataField = ctl.Name
PageHeader.Height = m_grid.HeadLines * m_grid.RowHeight
Set ctl = PageHeader.Controls.Add("DDActiveReports2.Label")
ctl.Left = iLeft
ctl.Top = 0
ctl.Height = PageHeader.Height
ctl.Width = col.Width
ctl.Caption = col.Caption
ctl.Font.Name = m_grid.HeadFont.Name
ctl.Font.Size = m_grid.HeadFont.Size
iLeft = iLeft + col.Width + 144
If iLeft > PrintWidth Then PrintWidth = iLeft
Next
End With
End PropertyPrivate Sub ActiveReport_FetchData(eof As Boolean)
Static lRow As Long
Dim ctl As Object
If m_grid Is Nothing Then Exit Sub
On Error GoTo ehFetchData
m_grid.Row = lRow
For Each ctl In Detail.Controls
Fields(ctl.Name).Value = m_grid.Columns(ctl.Tag)
Next
lRow = lRow + 1
eof = False
exFetchData:
Exit Sub
ehFetchData:
Err.Clear
Resume exFetchData
End SubPrivate Sub ActiveReport_ReportEnd()
If m_grid Is Nothing Then Exit Sub
m_grid.Visible = True
End SubPrivate Sub ActiveReport_ReportStart()
If m_grid Is Nothing Then Exit Sub
m_grid.Visible = False
End Sub
Error 5800 : Source: Report , Event: OnError , Line number: 0 Description:Fatal Exception during script excution.Error 5000 : Error in processing report.
[ Extended Info: CP internal=10]
这段代码我没编绎,你编绎后显示那行错了?
网上有许多动态生成datareport报表的基础例子,自己慢慢学一下.