前段时间做机房收费系统的时候,在周结账单的报表中添加窗体中选定的时间段要在报表中显示,在这一点上一直没有弄清楚。今天无意中从一些代码中弄明白了。主要是在窗体中动态的添加一个静态文本框来显示我们需要的文字。代码和主要的窗体界面如下,供大家一起研究学习
Option Explicit
Dim Report As grproLibCtl.GridppReport
Private Sub Rshow()
Dim strSQL As String
Dim strMsg As String
strSQL = "select * from checkweek_info where date<='" & Format(cboTimeStart.Text, "yyyy-mm-dd") & "' and date<='" & Format(cboTimeEnd.Text, "yyyy-mm-dd") & "'"
Set Report = New grproLibCtl.GridppReport
Report.LoadFromFile (App.Path & "\checkWeek.grf") '加载模版
Report.DetailGrid.Recordset.ConnectionString = ConnString '数据源
Report.DetailGrid.Recordset.QuerySQL = strSQL '通过SELECT查询创建记录集
'=================报表中自定义控件================
Dim Reportheader As IGRReportHeader
Dim StaticBox As IGRStaticBox
Set Reportheader = Report.InsertReportHeader
'插入一个静态文本框,显示需要显示的文字
Set StaticBox = Reportheader.Controls.Add(grctStaticBox).AsStaticBox
StaticBox.Text = cboTimeStart.Text & " 至 " & cboTimeEnd.Text
StaticBox.Width = 500
'======================================================
GRDisplayViewer1.Report = Report
GRDisplayViewer1.Start
End Sub
Private Sub cmdRefresh_Click()
GRDisplayViewer1.Refresh '刷新
End Sub
Private Sub cmdView_Click()
Report.PrintPreview (True) '打印预览
End Sub
Private Sub cmdPrint_Click()
Report.[Print] (True) '打印
End Sub