技術(shù) 點
- 技術(shù)
- 點
- V幣
- 點
- 積分
- 26472
|
在ACCESS自定義紙張源碼
窗體代碼:- Private Sub CmdNew_Click()
- Dim PrinterName As String
- Dim FormName As String
- Dim FormSize As SIZEL
- Dim PrinterHandle As Long
- Dim LngWidth As Long
- Dim LngHeight As Long
-
- If IsNull(Me.TxtNewStyle) Then
- MsgBox "請輸入要創(chuàng)建的打印格式"
- Me.TxtNewStyle.SetFocus
- Exit Sub
- End If
-
- If IsNull(Me.TxtWidth) Then
- MsgBox "請輸入要創(chuàng)建的打印格式的寬度尺寸(mm)"
- Me.TxtHeight.SetFocus
- Exit Sub
- End If
-
- If IsNull(Me.TxtHeight) Then
- MsgBox "請輸入要創(chuàng)建的打印格式高度尺寸(mm)"
- Me.TxtWidth.SetFocus
- Exit Sub
- End If
-
- If Not IsNumeric(Me.TxtWidth) Then
- MsgBox "打印格式寬度尺寸必須是數(shù)字類型"
- Me.TxtWidth.SetFocus
- Exit Sub
- End If
-
- If Not IsNumeric(Me.TxtHeight) Then
- MsgBox "打印格式高度尺寸必須是數(shù)字類型"
- Me.TxtWidth.SetFocus
- Exit Sub
- End If
-
-
- Dim RetVal As Long
- Dim Continue As Long
-
-
- PrinterName = GetSrvName(cmbPrinter)
- FormName = Me.TxtNewStyle
- LngWidth = Me.TxtWidth * 1000
- LngHeight = Me.TxtHeight * 1000
-
- If PrinterName = "" Then
- PrinterName = Printer.DeviceName '當(dāng)前打印機(jī)
- Else
- MakeDefaultPrinter PrinterName '設(shè)置默認(rèn)打印機(jī)
- End If
- RetVal = AddCustForm(FormName, Me.hwnd, LngWidth, LngHeight, PrinterName)
- Select Case RetVal
- Case FORM_NOT_SELECTED ' 0
- ' Selection failed!
- MsgBox "添加錯誤" & " ErrorCode:" & Err.LastDllError, vbExclamation, _
- "錯誤!"
- Case FORM_SELECTED ' 1
- MsgBox FormName & " 打印格式已經(jīng)存在于 " & PrinterName & " ", vbExclamation
- Case FORM_ADDED ' 2
- '//Form added and selected.
- MsgBox FormName & " 打印格式已經(jīng)添加到 " & PrinterName, vbInformation
- AddMyForm = True
- End Select
-
- ReGetPaperList
-
- End Sub
- Private Sub Form_Load()
- Dim Prn As Printer
- Dim Obj As AccessObject
-
- For Each Prn In Printers
- Me.cmbPrinter.AddItem Prn.DeviceName
- Next
-
- If cmbPrinter.ListCount > 0 Then
- cmbPrinter = Printer.DeviceName
- LstPaper.RowSource = GetPaperList(cmbPrinter)
- End If
-
- For Each Obj In CurrentProject.AllReports
- Me.LstReport.AddItem Obj.Name
- Next
- End Sub
- Private Sub cmbPrinter_AfterUpdate()
- Call ReGetPaperList
- End Sub
- Private Sub CmdDelete_Click()
- Dim colNetworkPrinters As New Collection
- Dim srvName As String, tmpName As String
- Dim FormName As String
- Dim PrinterName As String
- Dim i
- On Error Resume Next
- If Me.LstPaper.ListIndex < 0 Then
- MsgBox "請選擇要刪除的紙張格式"
- Exit Sub
- End If
- FormName = Mid(LstPaper, 1, InStr(1, LstPaper, " -") - 1)
-
- tmpName = ""
- srvName = GetSrvName(cmbPrinter)
-
- If srvName <> "" Then
- Call DeleteMyForm(srvName, FormName)
- End If
-
-
- ReGetPaperList
- End Sub
- Private Sub CmdReport_Click()
- Dim Rpt As Report
- ' Dim Prt As Report
- 'Dim accObj As AccessObject
-
- Dim strReportName As String
-
- If Me.LstReport.ListIndex < 0 Then
- MsgBox "請選擇報表"
- Exit Sub
- End If
-
-
- If Me.LstPaper.ListIndex < 0 Then
- MsgBox "請選擇打印的紙張類型"
- Exit Sub
- End If
-
- strReportName = LstReport
-
- If IsLoaded(strReportName) Then
- MsgBox "不能重復(fù)打開相同的報表"
- Exit Sub
- End If
-
-
- Select Case strReportName
-
- Case "報表1"
-
- Set Rpt = New Report_報表1
-
- Case "客戶標(biāo)簽"
-
- Set Rpt = New Report_客戶標(biāo)簽
-
- Case "概覽子報表"
-
- Set Rpt = New Report_概覽子報表
-
- Case Else
-
- Set Rpt = New Report_報表1
-
- End Select
-
-
-
-
- ' Set Rpt = Reports(strReportName)
-
- 'Set Rpt = New Report_報表1
- With Rpt.Printer
-
- .PaperSize = GetPaperSize(LstPaper)
- .Orientation = Me.frameOrientation.Value
-
- End With
- clnClient.Add Item:=Rpt, Key:=CStr(Rpt.hwnd)
- Rpt.Visible = True
- End Sub
- Private Sub ReGetPaperList()
- '刷新表單(紙張)列表
- If Not IsNull(Me.cmbPrinter) Then
- LstPaper.RowSource = ""
- LstPaper.RowSource = GetPaperList(cmbPrinter)
- End If
-
- End Sub
- 完整代碼請參考附件
復(fù)制代碼 |
本帖子中包含更多資源
您需要 登錄 才可以下載或查看,沒有帳號?注冊
x
評分
-
查看全部評分
|