設(shè)為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

1234下一頁
返回列表 發(fā)新帖
查看: 16778|回復(fù): 33
打印 上一主題 下一主題

[Access本身] 在ACCESS實現(xiàn)自定義紙張

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2011-10-9 11:02:59 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
在ACCESS自定義紙張源碼

窗體代碼:
  1. Private Sub CmdNew_Click()
  2.     Dim PrinterName  As String
  3.     Dim FormName As String
  4.     Dim FormSize As SIZEL
  5.     Dim PrinterHandle As Long
  6.     Dim LngWidth As Long
  7.     Dim LngHeight As Long
  8.    
  9.     If IsNull(Me.TxtNewStyle) Then
  10.        MsgBox "請輸入要創(chuàng)建的打印格式"
  11.        Me.TxtNewStyle.SetFocus
  12.        Exit Sub
  13.     End If
  14.    
  15.     If IsNull(Me.TxtWidth) Then
  16.        MsgBox "請輸入要創(chuàng)建的打印格式的寬度尺寸(mm)"
  17.        Me.TxtHeight.SetFocus
  18.        Exit Sub
  19.     End If
  20.    
  21.     If IsNull(Me.TxtHeight) Then
  22.        MsgBox "請輸入要創(chuàng)建的打印格式高度尺寸(mm)"
  23.        Me.TxtWidth.SetFocus
  24.        Exit Sub
  25.     End If
  26.    
  27.     If Not IsNumeric(Me.TxtWidth) Then
  28.        MsgBox "打印格式寬度尺寸必須是數(shù)字類型"
  29.        Me.TxtWidth.SetFocus
  30.        Exit Sub
  31.     End If
  32.    
  33.     If Not IsNumeric(Me.TxtHeight) Then
  34.        MsgBox "打印格式高度尺寸必須是數(shù)字類型"
  35.        Me.TxtWidth.SetFocus
  36.        Exit Sub
  37.     End If
  38.    
  39.    
  40.     Dim RetVal As Long
  41.     Dim Continue As Long
  42.    
  43.    
  44.     PrinterName = GetSrvName(cmbPrinter)
  45.     FormName = Me.TxtNewStyle
  46.     LngWidth = Me.TxtWidth * 1000
  47.     LngHeight = Me.TxtHeight * 1000
  48.    
  49.     If PrinterName = "" Then
  50.         PrinterName = Printer.DeviceName     '當(dāng)前打印機(jī)
  51.     Else
  52.         MakeDefaultPrinter PrinterName       '設(shè)置默認(rèn)打印機(jī)
  53.     End If

  54.     RetVal = AddCustForm(FormName, Me.hwnd, LngWidth, LngHeight, PrinterName)

  55.     Select Case RetVal
  56.         Case FORM_NOT_SELECTED    ' 0
  57.             ' Selection failed!
  58.             MsgBox "添加錯誤" & " ErrorCode:" & Err.LastDllError, vbExclamation, _
  59.                     "錯誤!"
  60.         Case FORM_SELECTED   ' 1
  61.            MsgBox FormName & " 打印格式已經(jīng)存在于 " & PrinterName & " ", vbExclamation
  62.         Case FORM_ADDED      ' 2
  63.             '//Form added and selected.
  64.             MsgBox FormName & " 打印格式已經(jīng)添加到 " & PrinterName, vbInformation
  65.             AddMyForm = True
  66.    End Select
  67.    
  68.   ReGetPaperList
  69.    
  70. End Sub

  71. Private Sub Form_Load()
  72.     Dim Prn As Printer
  73.     Dim Obj As AccessObject
  74.    
  75.     For Each Prn In Printers
  76.         Me.cmbPrinter.AddItem Prn.DeviceName
  77.     Next
  78.    
  79.     If cmbPrinter.ListCount > 0 Then
  80.        cmbPrinter = Printer.DeviceName
  81.        LstPaper.RowSource = GetPaperList(cmbPrinter)
  82.     End If
  83.    
  84.    For Each Obj In CurrentProject.AllReports
  85.       Me.LstReport.AddItem Obj.Name
  86.    Next
  87. End Sub


  88. Private Sub cmbPrinter_AfterUpdate()
  89.     Call ReGetPaperList
  90. End Sub

  91. Private Sub CmdDelete_Click()
  92.     Dim colNetworkPrinters As New Collection
  93.     Dim srvName As String, tmpName As String

  94.     Dim FormName As String
  95.     Dim PrinterName As String
  96.     Dim i

  97.     On Error Resume Next

  98.     If Me.LstPaper.ListIndex < 0 Then
  99.         MsgBox "請選擇要刪除的紙張格式"
  100.         Exit Sub
  101.     End If
  102.     FormName = Mid(LstPaper, 1, InStr(1, LstPaper, " -") - 1)
  103.    
  104.     tmpName = ""
  105.     srvName = GetSrvName(cmbPrinter)
  106.    
  107.     If srvName <> "" Then
  108.     Call DeleteMyForm(srvName, FormName)
  109.      End If
  110.      
  111.    
  112.     ReGetPaperList
  113. End Sub

  114. Private Sub CmdReport_Click()
  115.     Dim Rpt As Report
  116.    ' Dim Prt As Report
  117.     'Dim accObj As AccessObject
  118.    
  119.     Dim strReportName As String
  120.    
  121.     If Me.LstReport.ListIndex < 0 Then
  122.        MsgBox "請選擇報表"
  123.        Exit Sub
  124.     End If
  125.    
  126.    
  127.     If Me.LstPaper.ListIndex < 0 Then
  128.        MsgBox "請選擇打印的紙張類型"
  129.        Exit Sub
  130.     End If
  131.    
  132.     strReportName = LstReport
  133.    
  134.     If IsLoaded(strReportName) Then
  135.        MsgBox "不能重復(fù)打開相同的報表"
  136.        Exit Sub
  137.     End If
  138.    
  139.    
  140.     Select Case strReportName
  141.    
  142.       Case "報表1"
  143.    
  144.          Set Rpt = New Report_報表1
  145.    
  146.       Case "客戶標(biāo)簽"
  147.    
  148.          Set Rpt = New Report_客戶標(biāo)簽
  149.          
  150.       Case "概覽子報表"
  151.         
  152.          Set Rpt = New Report_概覽子報表
  153.         
  154.       Case Else
  155.       
  156.        Set Rpt = New Report_報表1
  157.       
  158.     End Select
  159.    
  160.    
  161.    
  162.    
  163.    ' Set Rpt = Reports(strReportName)
  164.    

  165. 'Set Rpt = New Report_報表1
  166.     With Rpt.Printer
  167.       
  168.         .PaperSize = GetPaperSize(LstPaper)
  169.         .Orientation = Me.frameOrientation.Value
  170.         
  171.     End With

  172.     clnClient.Add Item:=Rpt, Key:=CStr(Rpt.hwnd)
  173.     Rpt.Visible = True
  174. End Sub


  175. Private Sub ReGetPaperList()
  176. '刷新表單(紙張)列表
  177.     If Not IsNull(Me.cmbPrinter) Then
  178.        LstPaper.RowSource = ""
  179.        LstPaper.RowSource = GetPaperList(cmbPrinter)
  180.     End If
  181.    
  182. End Sub

  183. 完整代碼請參考附件
復(fù)制代碼

本帖子中包含更多資源

您需要 登錄 才可以下載或查看,沒有帳號?注冊

x

評分

參與人數(shù) 2經(jīng)驗 +15 收起 理由
purplerose + 5
todaynew + 10 很給力!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏5 分享分享 分享淘帖 訂閱訂閱
2#
發(fā)表于 2011-10-9 11:15:50 | 只看該作者
謝謝分享!

點擊這里給我發(fā)消息

3#
發(fā)表于 2011-10-9 11:24:44 | 只看該作者
精品之作!
4#
發(fā)表于 2011-10-9 13:44:37 | 只看該作者
謝謝分享,先下再學(xué).頂~~~~~``

點擊這里給我發(fā)消息

5#
發(fā)表于 2011-10-9 14:48:07 | 只看該作者
好東西呀!
6#
發(fā)表于 2011-10-9 15:06:12 | 只看該作者
不錯
7#
發(fā)表于 2011-10-9 15:09:00 | 只看該作者
學(xué)習(xí)一下
8#
發(fā)表于 2011-10-9 15:15:08 | 只看該作者
太需要了...
9#
發(fā)表于 2011-10-9 15:37:09 | 只看該作者
收藏先,以后用得著,謝謝分享.
10#
發(fā)表于 2011-10-9 16:43:04 | 只看該作者
謝謝分享
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2025-7-13 04:56 , Processed in 0.482582 second(s), 39 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表