我的是水晶报表要动态连接一个一个数据库,每次我的VB系统运行时,总是报错说“无效目录”不知道是什么原因,我每次保用水晶报表莫板设计器保存做的好的报表模板保存后去查看这个模板文件,但这个模板文件后缀名没有以.rpt结尾。而文件名直接是report1显示。然后我都是存在 E:\rpt\report1.rpt
以下是我的代码:
Dim oApp As New CRAXDRT.Application
Dim oRpt As CRAXDRT.Report
Dim reportName As String
Screen.MousePointer = vbHourglass
Set oRpt = oApp.OpenReport(App.Path & "\rpt\report1.rpt", 1)
以下是我的代码:
Dim oApp As New CRAXDRT.Application
Dim oRpt As CRAXDRT.Report
Dim reportName As String
Screen.MousePointer = vbHourglass
Set oRpt = oApp.OpenReport(App.Path & "\rpt\report1.rpt", 1)
rptform!report1.ReportFileName = ReportPath & filename
rptform!report1.Connect = cn.ConnectionString
rptform!report1.Formulas(1) = "单位='" & Left(DWMC, 12) & "'"
rptform!report1.Formulas(2) = "单位2='" & Right(DWMC, Len(DWMC) - 12) & "'"
rptform!report1.Destination = 1
rptform!report1.Action = 1
或改成
Set oRpt = oApp.OpenReport("e:\rpt\report1.rpt", 1)
Dim oApp As New CRAXDRT.Application
Dim reportName As StringScreen.MousePointer = vbHourglass
reportName = "\rpt\" & m_sRptname '引用的rpt文件
Set oRpt = oApp.OpenReport(App.Path & reportName, 1)with oRpt.Database.Tables(1)
.ConnectionProperties("data source") = "192.168.0.20"
.ConnectionProperties("initial catalog") = "mydb"
.ConnectionProperties("user id") = "sa"
.ConnectionProperties("password") = "123456"
end with
oRpt.ReadRecords
CRViewer91.ReportSource = oRpt '启用水晶报表的预览功能
On Error Resume Next
CRViewer91.ViewReport
Screen.MousePointer = vbDefault