第三步:在VB窗体上添加GRDisplayViewer控件 @H_403_0@第四步:编写代码:第一次犯错时的代码:(其中错误是不能解决指定日期的记录检索不出来)
Option Explicit Dim Report As grproLibCtl.GridppReport Dim Reportheader As IGRReportHeader Dim StaticBox As IGRStaticBox Private Sub Rshow() Dim strsql As String Dim strMsg As String strsql = "select * from checkday_info where date>='" & Format$(cmbBeginDate.Text,"yyyy-mm-dd") & "' and date<='" & Format$(cmbEndDate.Text,"yyyy-mm-dd") & "'" Set Report = New grproLibCtl.GridppReport Report.LoadFromFile (App.Path & "\checkWeek.grf") '加载模版 Report.DetailGrid.Recordset.ConnectionString = "filedsn=charge.dsn;UID=sa;PWD=123456" '数据源 Report.DetailGrid.Recordset.Querysql = strsql '通过SELECT查询创建记录集 '=================报表中自定义控件================ Set Reportheader = Report.InsertReportHeader '插入一个静态文本框,显示需要显示的文字 Set StaticBox = Reportheader.Controls.Add(grctStaticBox).AsStaticBox StaticBox.Text = cmbBeginDate.Text & " 至 " & cmbEndDate.Text StaticBox.Width = 500 '============================ GRDisplayViewer1.Report = Report GRDisplayViewer1.Start End Sub Private Sub cmdcmdPrintRefresh_Click() StaticBox.Text = cmbBeginDate.Text & " 至 " & cmbEndDate.Text GRDisplayViewer1.Refresh '刷新 End Sub Private Sub cmdPrint_Click() Report.[Print] (True) '打印 End Sub Private Sub cmdViewPrint_Click() Report.PrintPreview (True) '打印预览 End Sub Private Sub cmbBeginDate_DropDown() MonthView1.Visible = True End Sub Private Sub cmbEndDate_DropDown() MonthView2.Visible = True End Sub Private Sub MonthView1_DateClick(ByVal DateClicked As Date) cmbBeginDate.Text = MonthView1.Year & "-" & MonthView1.Month & "-" & MonthView1.Day MonthView1.Visible = False End Sub Private Sub MonthView2_DateClick(ByVal DateClicked As Date) cmbEndDate.Text = MonthView2.Year & "-" & MonthView2.Month & "-" & MonthView2.Day MonthView2.Visible = False End Sub Private Sub Form_Load() MonthView1.Visible = False MonthView2.Visible = False ' cmbBeginDate.Text = Format$("2012-08-08","YYYY-MM-DD") ' cmbEndDate.Text = Format$(Date,"YYYY-MM-DD") Me.Width = 15000 Me.Height = 13000 Call Rshow End Sub第二次,是在听同学说了一个stop 属性的时候,自己重新试了一下,结果相对满意,能够实现返回指定日期的源码: @H_403_0@
Option Explicit Dim Report As grproLibCtl.GridppReport Dim Reportheader As IGRReportHeader Dim StaticBox As IGRStaticBox Private Sub Rshow() Dim strsql As String Dim strMsg As String strsql = "select * from checkday_info where date>='" & Format$(cmbBeginDate.Text,显示需要显示的文字 Set StaticBox = Reportheader.Controls.Add(grctStaticBox).AsStaticBox StaticBox.Text = cmbBeginDate.Text & " 至 " & cmbEndDate.Text StaticBox.Width = 500 '============================ GRDisplayViewer1.Report = Report GRDisplayViewer1.Start End Sub Private Sub cmdcmdPrintRefresh_Click() GRDisplayViewer1.Stop StaticBox.Text = cmbBeginDate.Text & " 至 " & cmbEndDate.Text Call Rshow End Sub Private Sub cmdPrint_Click() Report.[Print] (True) '打印 End Sub Private Sub cmdViewPrint_Click() Report.PrintPreview (True) '打印预览 End Sub Private Sub cmbBeginDate_DropDown() MonthView1.Visible = True End Sub Private Sub cmbEndDate_DropDown() MonthView2.Visible = True End Sub Private Sub MonthView1_DateClick(ByVal DateClicked As Date) cmbBeginDate.Text = MonthView1.Year & "-" & MonthView1.Month & "-" & MonthView1.Day MonthView1.Visible = False End Sub Private Sub MonthView2_DateClick(ByVal DateClicked As Date) cmbEndDate.Text = MonthView2.Year & "-" & MonthView2.Month & "-" & MonthView2.Day MonthView2.Visible = False End Sub
Private Sub Form_Load() MonthView1.Visible = False MonthView2.Visible = False cmbBeginDate.Text = Format$("2012-08-08","YYYY-MM-DD") cmbEndDate.Text = Format$(Date,"YYYY-MM-DD") Me.Width = 15000 Me.Height = 13000 Call Rshow End Sub可以对比出来,那个区别是在 cmdcmdPrintRefresh_Click()事件下,先将报表给停止,然后重新调用声明的子过程。 @H_403_0@如果不停止的话,就会报错: