安装水晶报表后,VB中应该“工程”菜单下有一个“添加crystal report ”这么一项。 在引用部件中,选中“crystal report Viewer Control 9”
安装水晶报表后,先在“工程”菜单下引用“crystal report Viewer Control 9”然后添加 “crystal report Viewer Control 9”这个部件。然后写下如下代码: Dim cry As New CRAXDDRT.Application Dim rep As New CRAXDDRT.Report Set rep = cry.OpenReport(App.Path & "\文件名.rpt") CRViewer91.ReportSource = rep CRViewer91.GetCurrentPageNumber CRViewer91.ShowNextPage CRViewer91.ViewReport
在fsysky(风沙雨)的回复中, Set rep=cry.OpenReport(App.Path & "\文件名.rpt") 该为: Set rep=cry.OpenReport("水晶报表模板保存的路径\模板文件名.rpt") 若不改,则应该把保存的水晶报表模板移到工程所在的文件夹去。
.WindowShowPrintSetupBtn = True
.Connect = getConnectDSN '连接的数据库
.SQLQuery = SelectSQL
.ReportFileName = App.Path & "\report\*.rpt"
.Formulas(0) = "printname= '" + LoginName + "'"
.Formulas(1) = "rq1= '" + m + "'"
.Formulas(2) = "rq2= '" + n + "'"
.WindowState = crptMaximized
.PageZoom 100
.PrintReport
.Reset
End With
在引用部件中,选中“crystal report Viewer Control 9”
Dim cry As New CRAXDDRT.Application
Dim rep As New CRAXDDRT.Report
Set rep = cry.OpenReport(App.Path & "\文件名.rpt")
CRViewer91.ReportSource = rep
CRViewer91.GetCurrentPageNumber
CRViewer91.ShowNextPage
CRViewer91.ViewReport
Set rep=cry.OpenReport(App.Path & "\文件名.rpt") 该为:
Set rep=cry.OpenReport("水晶报表模板保存的路径\模板文件名.rpt")
若不改,则应该把保存的水晶报表模板移到工程所在的文件夹去。