Crystal Report print (vb)

Private Sub Form_Activate()
  Dim fv_iReturn  As Integer
  Dim fv_sFormulaName As String
  Dim fv_sTemp_Report_Name As String
  Dim fv_iJob_Handle As Integer     '' 僾儕儞僩僕儑僽僴儞僪儖
  Dim fv_iTable1 As Integer         '' 僥亅僽儖斣崋1
  Dim fv_iTable2 As Integer         '' 僥亅僽儖斣崋2
  Dim fv_uMyInfo1 As PELogOnInfo    '' 儘僌僆儞忣曬1
  Dim fv_uMyInfo2 As PELogOnInfo    '' 儘僌僆儞忣曬2
  Dim fv_lTextHandle As Long        '' 僄儔亅僥僉僗僩僴儞僪儖
  Dim fv_iTextLength As Integer     '' 僄儔亅僥僉僗僩僶僀僩挿
  Dim fv_sErrorText As String       '' 僄儔亅僥僉僗僩
  Dim fv_sDeviceName As String
  Dim fv_sSaveDeviceName As String
  Dim fv_oPrinter As Printer
  Dim fv_sSetVal  As String
  Dim fv_lRet     As Long
 
  Const HWND_BROADCAST = &HFFFF&
  Const WM_WININICHANGE = &H1A
 
  If m_bOnce_Flg = True Then Exit Sub
 
  m_bOnce_Flg = True
 
  g_bResult = True
 
  ''-----  -----
    On Error GoTo Error_Section:
    Label1(0).Caption = g_sLPP_ReportName2
    Label1(1).Caption = "11"
    Me.Refresh
 
  ''----- -----
      If g_sLPP_vFormSize <> "" Then
         Select Case g_sLPP_vFormSize
             Case gc_sSizeA4
                  fv_sDeviceName = g_sPrn_A4
                  GoSub GetPrinterInfo
             Case gc_sSizeB4
                  fv_sDeviceName = g_sPrn_B4
                  GoSub GetPrinterInfo
             Case gc_sSizeSF 
                  fv_sDeviceName = g_sPrn_SF
                  GoSub GetPrinterInfo
             Case Else
                  fv_sDeviceName = Printer.DeviceName
         End Select
      Else
              fv_sDeviceName = g_sPrn_SF
        GoSub GetPrinterInfo
      End If
 
  ''----- -----
      If PEOpenEngine() = 0 Then GoTo CR_Error_Section:
     
  ''----- -----
      fv_iJob_Handle = PEOpenPrintJob(g_sLPP_ReportName1 + Chr$(0))
      If fv_iJob_Handle = 0 Then
        GoTo CR_Error_Section:
      End If
  ''----- Oracle -----
      If g_sLPP_Data_Type = 0 Or g_sLPP_Data_Type = 2 Then
        fv_uMyInfo1.StructSize = PE_SIZEOF_LOGON_INFO    ' Set up the structure size
        fv_uMyInfo1.ServerName = "" + Chr$(0)            ' Use ServerName stored in report
        fv_uMyInfo1.DatabaseName = "" + Chr$(0)          ' Use DatabaseName stored in report'
        fv_uMyInfo1.UserID = g_sOraUser + Chr$(0)               ' Use UserID stored in report
        fv_uMyInfo1.Password = g_sOraPass + Chr$(0)              ' Set up the password here
        fv_iTable1 = 0                                   ' We will set the password for the first table
   
        If PESetNthTableLogOnInfo(fv_iJob_Handle, fv_iTable1, fv_uMyInfo1, True) = False Then GoTo CR_Error_Section:
        
        If CR_Change_Location(fv_iJob_Handle, g_sOraUser) = False Then GoTo CR_Error_Section:
      
        ''----- Crystal Report  -----
        If Fn_Chg_SubLocation(fv_iJob_Handle) = False Then GoTo CR_Error_Section:
         End If
     
  ''----- TextFile -----
      If g_sLPP_Data_Type = 1 Or g_sLPP_Data_Type = 2 Then
        fv_uMyInfo2.StructSize = PE_SIZEOF_LOGON_INFO    ' Set up the structure size
        If g_sLPP_Data_Type = 1 Then
          fv_iTable2 = 0                                 ' We will set the password for the first table
        Else
          fv_iTable2 = 1
        End If
        ''----- Text-----
        If PEGetNthTableLogOnInfo(fv_iJob_Handle, fv_iTable2, fv_uMyInfo2) = False Then GoTo CR_Error_Section:
      End If
 
      If g_iLPP_Out_Source = 0 Then
        ''----- -----
        If PEOutputToPrinter(fv_iJob_Handle, 1) <> 1 Then GoTo CR_Error_Section:
      Else
        ''  -----
        If PEOutputToWindow(fv_iJob_Handle, g_sLPP_ReportName2, 100, 100, 444, 350, 0, 0) <> 1 Then GoTo CR_Error_Section:
      End If
   
  ''-----  -----
      If Trim(g_sLPP_Formula) <> "" Then
        If PESetSelectionFormula(fv_iJob_Handle, g_sLPP_Formula) = False Then GoTo CR_Error_Section:
      End If
  ''----- 
      If Trim(g_sLPP_Gmu_Date) <> "" Then
        fv_sFormulaName = "111" + Chr$(0)
        g_sLPP_Gmu_Date = "'" & Format(g_sLPP_Gmu_Date, "@@@@/@@/@@") & "'" & Chr$(0)
        If PESetFormula(fv_iJob_Handle, fv_sFormulaName, g_sLPP_Gmu_Date) = False Then GoTo CR_Error_Section:
      End If
  ''-----   '   fv_sFormulaName = "弌椡帪娫" + Chr$(0)
  '   fv_sFormulaTime = "'" & Format(Now, "HH:MM:SS") & "'" & Chr$(0)
  '   If PESetFormula(fv_iJob, fv_sFormula_name, fv_sFormula_Time) = False Then GoTo CR_Error_Section:
 
  ''-----       fv_sTemp_Report_Name = UCase(Left(Right(g_sLPP_ReportName1, 12), 8))
      If List_Print_Formula(fv_iJob_Handle, fv_sTemp_Report_Name) = False Then GoTo CR_Error_Section:
 
  ''----- 
     If PETestNthTableConnectivity(fv_iJob_Handle, 0) <> 1 Then GoTo CR_Error_Section:
 
  ''-----  -----
     Label1(1).Caption = "111"
     Me.Refresh
     If PEStartPrintJob(fv_iJob_Handle, True) <> 1 Then GoTo CR_Error_Section:
 
  ''----- -----
     PEClosePrintJob (fv_iJob_Handle)       ' Close the print job
 
  ''-----  -----
     GoSub ResetPrinterInfo
 
  ''-----  -----
     If g_iLPP_Out_Source = 1 Then
       AppActivate g_sLPP_ReportName2
       DoEvents
     End If
 
     Unload Me
 
Exit Sub
'----- GetPrinterInfo:
 
  fv_sSaveDeviceName = Printer.DeviceName '  
  If fv_sSaveDeviceName = fv_sDeviceName Then Return ' 
  If fv_sDeviceName = gc_sPrnNonSel Then Return '  
  Do
    For Each fv_oPrinter In Printers
      If fv_oPrinter.DeviceName = fv_sDeviceName Then Exit Do
    Next
    Return '  Loop
   '----- ----
  If fv_oPrinter.DeviceName = fv_sDeviceName Then

    fv_sSetVal = fv_oPrinter.DeviceName & "," & fv_oPrinter.DriverName & "," & fv_oPrinter.Port
    fv_lRet = WriteProfileString("windows", "device", fv_sSetVal)
    fv_lRet = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows")
'    If PESelectPrinter(fv_iJob_Handle, fv_oPrinter.DeviceName, fv_oPrinter.DeviceName, fv_oPrinter.Port, 0) = False Then GoTo CR_Error_Section
  End If
Return

'
ResetPrinterInfo:
 
  If fv_sSaveDeviceName = fv_sDeviceName Then Return '  If fv_sDeviceName = gc_sPrnNonSel Then Return   
  Do
    For Each fv_oPrinter In Printers
      If fv_oPrinter.DeviceName = fv_sSaveDeviceName Then Exit Do
    Next
    Return 
  Loop

  If fv_oPrinter.DeviceName = fv_sSaveDeviceName Then

    fv_sSetVal = fv_oPrinter.DeviceName & "," & fv_oPrinter.DriverName & "," & fv_oPrinter.Port
    fv_lRet = WriteProfileString("windows", "device", fv_sSetVal)
    fv_lRet = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows")
  End If
Return
CR_Error_Section::
   
    fv_sErrorText = ""
    fv_lTextHandle = 0
    fv_iTextLength = 0
        If PEGetErrorText(fv_iJob_Handle, fv_lTextHandle, fv_iTextLength) = 1 Then
      fv_sErrorText = Space(fv_iTextLength)
      fv_iReturn = PEGetHandleString(fv_lTextHandle, fv_sErrorText, fv_iTextLength)
    End If

    MsgBox fv_sErrorText + Chr$(13) + "Report File = " & g_sLPP_ReportName1, _
           vbOKOnly + vbExclamation, _
           Code = " & PEGetErrorCode(fv_iJob_Handle)
    PEClosePrintJob (fv_iJob_Handle)
    g_bResult = False
    Unload Me
    Exit Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值