ช่วยบอกวิธีใช้โค๊ดนี้หน่อยครับเกี่ยวกับการตั้งค่ากระดาษ
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 279   4
URL.หัวข้อ / URL
ช่วยบอกวิธีใช้โค๊ดนี้หน่อยครับเกี่ยวกับการตั้งค่ากระดาษ

ผมเห็นมีการให้โค๊ดนี้ไว้แต่ไม่ทราบว่าต้องวางไว้ตรงไหนบ้าง เพราะผมต้องการกำหนดให้ขนาดกระดาษเป็น A4 เสมอ และเป็นแนวนอนครับ ส่วน Scale ด้านบน,ล่าง,ซ้าย,ขวา ให้เท่ากับ 0 ใครทราบวิธีการใช้งาน ช่วยแนะนำผมด้วยครับ


Option Compare Database
Type str_DEVMODE
RGB As String * 94
End Type
Type str_PRTMIP
strRGB As String * 28
End Type

Type type_DEVMODE
strDeviceName As String * 16
intSpecVersion As Integer
intDriverVersion As Integer
intSize As Integer
intDriverExtra As Integer
lngFields As Long
intOrientation As Integer
intPaperSize As Integer
intPaperLength As Integer
intPaperWidth As Integer
intScale As Integer
intCopies As Integer
intDefaultSource As Integer
intPrintQuality As Integer
intColor As Integer
intDuplex As Integer
intResolution As Integer
intTTOption As Integer
intCollate As Integer
strFormName As String * 16
lngPad As Long
lngBits As Long
lngPW As Long
lngPH As Long
lngDFI As Long
lngDFr As Long
End Type
Type type_PRTMIP
xLeftMargin As Long
yTopMargin As Long
xRightMargin As Long
yBotMargin As Long
fDataOnly As Long
xWidth As Long
yHeight As Long
fDefaultSize As Long
cxColumns As Long
yColumnSpacing As Long
xRowSpacing As Long
rItemLayout As Long
fFastPrint As Long
fDatasheet As Long
End Type

Sub SetPaperRpt(RptName As String, PaperSize As String, PaperWidth As String, PaperLength As String, Orientation As String, _
DefaultSource As String, DefaultSize As Boolean, ItemSizeWidth As String, ItemSizeHeight As String, _
TopMargin As String, BotMargin As String, LeftMargin As String, RightMargin As String, PrtName As String)
Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim intResponse As Integer
Dim rpt As Report

DoCmd.OpenReport RptName, acDesign
Set rpt = Reports(RptName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields Or DM.intPaperSize Or DM.intPaperLength Or DM.intPaperWidth
Select Case PaperSize
Case 256
DM.intPaperSize = 256 ' Set custom page. 256 (User -defined)
DM.intPaperWidth = PaperWidth * 254 ' 254 =1 inch
DM.intPaperLength = PaperLength * 254
Case 8 To 10
DM.intPaperSize = PaperSize ' Set custom page. 10 (A4 Small [210 x 297 mm]) , 9 (A4 [210 x 297 mm]) , 8 (A3 [297 x 420 mm])
Case 1 To 41
DM.intPaperLength = ""
Case Else
DM.intPaperSize = 9
End Select
If Not IsNull(PrtName) Or PrtName <> "" Then
DM.strDeviceName = PrtName
End If
If IsNull(Orientation) Or Orientation = 1 Then ' 1 (portrait) or 2 (landscape)
DM.intOrientation = 1
Else
DM.intOrientation = 2
End If
If IsNull(DefaultSource) Or DefaultSource = 4 Then ' 4 (Manual bin ) , 8 (Tractor bin)
DM.intDefaultSource = 4
Else
DM.intDefaultSource = 8
End If
LSet DevString = DM ' Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra

PrtMipString.strRGB = rpt.PrtMip
LSet PM = PrtMipString ' Set margins. 567=1 cm
If IsNull(TopMargin) Or IsNull(BotMargin) Or IsNull(LeftMargin) Or IsNull(RightMargin) Then
PM.yTopMargin = 0 * 567 / 10
PM.yBotMargin = 4.8 * 567 / 10
PM.xLeftMargin = 0 * 567 / 10
PM.xRightMargin = 3.1 * 567 / 10
Else
PM.yTopMargin = TopMargin * 567 / 10
PM.yBotMargin = BotMargin * 567 / 10
PM.xLeftMargin = LeftMargin * 567 / 10
PM.xRightMargin = RightMargin * 567 / 10
End If
If IsNull(DefaultSize) Or DefaultSize = -1 Or IsNull(ItemSizeWidth) Or IsNull(ItemSizeHeight) Then
PM.fDefaultSize = -1
Else
PM.fDefaultSize = 0
PM.xWidth = ItemSizeWidth * 567
PM.yHeight = ItemSizeHeight * 567
End If
LSet PrtMipString = PM ' Update property.
rpt.PrtMip = PrtMipString.strRGB
DoCmd.Close acReport, RptName, acSaveYes
End If
Set rpt = Nothing
End Sub


Sub TestRpt()
Call SetPaperRpt("A4P", 9, , , 1, 8, True, , , 20, 10, 20, 3.1, "") 'ขนาดกระดาษ A4 ตั้ง
Call SetPaperRpt("A4L", 9, , , 2, 4, True, , , 20, 10, 20, 3.1, "") 'ขนาดกระดาษ A4 นอน

Call SetPaperRpt("9_5x11P", 256, 11, 11, 1, 8, True, , , 20, 7.9, 3.1, 3.1, "EPSON LQ-2080 ESC/P 2") 'ขนาดกระดาษต่อเนื่อง 9.5"x11" ตั้ง
Call SetPaperRpt("15x11P", 256, 15, 11, 1, 8, False, 35, 0.5, 20, 6.9, 4, 3.1, "EPSON LQ-2080 ESC/P 2") 'ขนาดกระด*11"าษต่อเนื่อง 15" x11" ตั้ง
End Sub

4 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R03998
เอาโค้ดเหล่านี้ไปไว้ใน Module
เวลาจะใช้งานให้ใช้คำสั่ง

SetPaperRpt("ชื่อรายงาน", "ขนาดกระดาษ", "ความกว้างของกระดาษ", "ความยาวของกระดาษ", "แนวกระดาษ ตั้งหรือขวาง", "แหล่งที่มา", "ขนาดตั้งต้น True หรือ False", "ความกว้าง" , "ความสูง", "กั้นหน้าด้านบน", "ขอบล่าง", "ขอบซ้าย", "ขอบขวา", "ชื่อปริ้นเตอร์เป้าหมาย")

ให้ดูตัวอย่างที่การแทนค่าในโค้ดที่นำมาให้ดูครับ

หรือดูตัวอย่างในกระทู้ http://www.thai-access.com/suphap.php?topic_id=1631 ประกอบด้วยครับ
2 @R04002
อาจารย์สุภาพครับ
SetPaperRpt("ชื่อรายงาน", "ขนาดกระดาษ", "ความกว้างของกระดาษ", "ความยาวของกระดาษ", "แนวกระดาษ ตั้งหรือขวาง", "แหล่งที่มา", "ขนาดตั้งต้น True หรือ False", "ความกว้าง" , "ความสูง", "กั้นหน้าด้านบน", "ขอบล่าง", "ขอบซ้าย", "ขอบขวา", "ชื่อปริ้นเตอร์เป้าหมาย")

หมายถึงให้นำไปไว้ที่ event on click ใช่หรือไม่ครับ

ขอบคุณครับ
3 @R04004
ครับ

Private Sub Command1_Click()
Call SetPaperRpt(ใส่ค่าต่างๆ ตรงนี้)
End Sub

4 @R04020
ผมลองนำ
Call SetPaperRpt("A4L", 9, , , 2, 4, True, , , 20, 10, 20, 3.1, "") 'ขนาดกระดาษ A4 นอน
โดยที่ A4L เป็นชื่อรายงานของผม แต่ Compile ไม่ผ่านครับ
ทำอย่างไรดีครับช่วยแนะนำอีกทีครับ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0578s