我的是水晶报表要动态连接一个一个数据库,每次我的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)

解决方案 »

  1.   

     Set oRpt = oApp.OpenReport("E:\rpt\report1.rpt", 1) 
      

  2.   

    参考 http://www.cnblogs.com/babyt/archive/2005/03/11/116880.html
      

  3.   

       Dim cn  As New ADODB.Recordset
        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
      

  4.   

    是不是要把rpt文件放到执行文件目录下面啊?你的可执行程序在什么路径呢
      

  5.   

    你用了app.path,就是要把rpt目录放在可执行文件目录下
    或改成
    Set oRpt = oApp.OpenReport("e:\rpt\report1.rpt", 1)  
      

  6.   

    拉模式代码
    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