这是以变量传递方式打印的例子,划报表时,选择插入Formulas,
Formulas的名字分别是:jkdcode、jkdtime等(类似插入了一个字段)。Public Sub sub_print_frminvjkd()
Dim oRpt As CrystalReport
Set oRpt = FrmSysMain.Rptmain 'rptmain 是放置在主窗口上的水晶报表控件
With frmInvJKDb
      oRpt.ReportFileName = gsReportPath + "jkd.rpt"
      oRpt.Formulas(0) = "jkdcode='" & Trim(.txt(0)) & "'"
      oRpt.Formulas(1) = "jkdtime='" & .dtpTime.GetDatetime(False) & "'"
      oRpt.Formulas(2) = "cstcode='" & Trim(.txt(1)) & "'"
      oRpt.Formulas(3) = "cstname='" & Trim(.txt(2)) & "'"
      oRpt.Formulas(4) = "invtype='" & Trim(.txt(3)) & "'"
      oRpt.Formulas(5) = "invcode='" & Trim(.txt(4)) & "'"
      oRpt.Formulas(6) = "cash='" & Trim(.txt(5)) & "'"
      oRpt.Formulas(7) = "cashnote='" & Trim(.txt(6)) & "'"
      oRpt.Formulas(8) = "check='" & Trim(.txt(7)) & "'"
      oRpt.Formulas(9) = "checknote='" & Trim(.txt(8)) & "'"
      oRpt.Formulas(10) = "card='" & Trim(.txt(9)) & "'"
      oRpt.Formulas(11) = "cardnote='" & Trim(.txt(10)) & "'"
      oRpt.Formulas(12) = "else='" & Trim(.txt(11)) & "'"
      oRpt.Formulas(13) = "elsenote='" & Trim(.txt(12)) & "'"
      oRpt.Formulas(14) = "sum='" & Trim(.txt(13)) & "'"
      oRpt.Formulas(15) = "ysk='" & Trim(.txt(14)) & "'"
      oRpt.Formulas(16) = "jkdman='" & Trim(.txt(15)) & "'"
      oRpt.Formulas(17) = "cmoney='" & Trim(.txt(16)) & "'"
End With
s_Settype
FrmSysMain.Rptmain.PrinterCopies = CInt(txtcopy.Text)
FrmSysMain.Rptmain.PrintReport
Unload Me
end subPrivate Sub s_Settype()
Dim i  As Integer, j As Integer
For i = 0 To 2
    If chk(i).Value = 1 Then Exit For
Next iSelect Case i
       Case 0: j = 10  '输出为excell 文件
       Case 1: j = 17   '输出为Word文件
       
       Case 2: j = 2   '输出为文本文件
       Case Else: j = -1
End Select
If j = -1 Then
   FrmSysMain.Rptmain.Destination = crptToPrinter
Else
   FrmSysMain.Rptmain.PrintFileType = j
   FrmSysMain.Rptmain.Destination = crptToFile
End If
End Sub