เรียกพิมพ์ report_bill ให้ preview report โดยเป็น 2 ฉบับ คือ ต้นฉบับ กับ สำเนา


0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

26 เม.ย. 62 , 21:31:30
อ่าน 995 ครั้ง

kunlek

สร้างปุ่ม command ไว้ที่ toolbar กด click แสดง report_bill ทั้ง ต้นฉบับ กับสำเนา(เพราะไม่ได้ printer หัวเข็มจึงต้องพิมพ์ที่2บิล)

 

29 เม.ย. 62 , 15:21:48
ตอบกลับ #1

ปิ่นณรงค์

สร้างปุ่ม command ไว้ที่ toolbar กด click แสดง report_bill ทั้ง ต้นฉบับ กับสำเนา(เพราะไม่ได้ printer หัวเข็มจึงต้องพิมพ์ที่2บิล)

วิธีใหม่ที่ Report 1 อันสามารถปริ้น Caption ได้ทั้ง สำเนา และต้นฉบับ และ การดู Preview Report 1 อันแสดง 2 อย่าง

วิธีการ 1.สร้าง Lable กำหนดชื่อ Lable เช่น ReportLabel ตัวรายงานชื่อ  Report_Bill
        2.ที่ปุ่ม Command Event Onclick ใส่โค้ดไปว่า
โค๊ด: [Select]
Private Sub Command_Click()
DoCmd.OpenReport "Report_Bill", acViewDesign
Reports![report_bill]![ReportLabel].Caption = "ต้นฉบับ"
DoCmd.OpenReport "Report_Bill", acViewNormal

DoCmd.OpenReport "Report_Bill", acViewDesign
Reports![report_bill]![ReportLabel].Caption = "สำเนา"
DoCmd.OpenReport "Report_Bill", acViewNormal
End Sub


ส่วนการแสดงหน้ารายงาน โดยมีรายงานเดียว แสดง ทั้ง 2 แบบ
สมมุติชื่อรายงาน Report_Bill ขั้นตอนดังนี้
1.สร้าง Module ขึ้นมา
ใส่โค้ดนี้เข้าไป
โค๊ด: [Select]
Option Compare Database

Option Explicit

Public clnClient As New Collection

Function OpenReport2()

    Dim Report As Report
   
    Set Report = New Report_report_bill
     Report.Visible = True
    Report!ReportLabel.Caption = "สำเนา"
   
   
    clnClient.Add ITEM:=Report, Key:=CStr(Report.Hwnd)
   
    Set Report = Nothing
End Function

2.สร้างปุ่ม Command ขึ้นมา ใส่โค้ดนี้เข้าไป

โค๊ด: [Select]
Private Sub Command14_Click()
DoCmd.OpenReport "Report_Bill", acViewDesign
Reports![report_bill]![ReportLabel].Caption = "ต้นฉบับ"
DoCmd.Save
DoCmd.OpenReport "Report_Bill", acViewPreview
Call OpenReport2
End Sub

ตัวอย่างด้านล่าง
« แก้ไขครั้งสุดท้าย: 29 เม.ย. 62 , 16:02:04 โดย ปิ่นณรงค์ »
:love: :grin:
 

29 เม.ย. 62 , 21:21:04
ตอบกลับ #2

kunlek

อจ.ขอ demo เป็น .mdb ได้ไหมครับ

 

29 เม.ย. 62 , 23:41:08
ตอบกลับ #3

ปิ่นณรงค์

ลองดูครับ ไม่รู้จะใช้กับ 2007 ได้ไหมนะครับลองดู
:love: :grin:
 

30 เม.ย. 62 , 08:23:41
ตอบกลับ #4

kunlek

ขึ้น popup error runtime error "438"   Object doesn't support this property or method 
ใช้ access 2003 ครับ

 

30 เม.ย. 62 , 08:40:33
ตอบกลับ #5

kunlek

compile error  user-defined type not defined
Set Report = New Report_report_bill
     Report.Visible = True
    Report!ReportLabel.Caption = "สำเนา"
   
   
    clnClient.Add ITEM:=Report, Key:=CStr(Report.Hwnd)

ที่ module

 

30 เม.ย. 62 , 08:43:26
ตอบกลับ #6

ปิ่นณรงค์

ลองแก้เป็น
Option Compare Database
Option Explicit
Public clnClient As New Collection
Function OpenReport2()
    Dim Rpt As Report
    Set Rpt = New Report_report_bill
     Rpt.Visible = True
    Rpt!ReportLabel.Caption = "สำเนา"
    clnClient.Add ITEM:=Rpt, Key:=CStr(Rpt.Hwnd)
    Set Rpt = Nothing
End Function

ไม่รู้ Reference อันไหนไม่มีหรือเปล่า เดี่ยวขอลองติดตั้ง เวอร์ชั้นเก่าทดสอบดูก่อนนะคับ

ถ้ายังไม่ได้  @Line มาครับ เดี่ยวคุยกันเอาให้จนทำได้เลย ส่งไลน์ ID ทางข้อความคับ:cool: :cool:
« แก้ไขครั้งสุดท้าย: 30 เม.ย. 62 , 08:53:26 โดย ปิ่นณรงค์ »
:love: :grin:
 

30 เม.ย. 62 , 08:55:10
ตอบกลับ #7

kunlek

ผมเอา code จากกระทู้ตอบกลับ #1
DoCmd.OpenReport "Report_Bill", acViewDesign
Reports![report_bill]![ReportLabel].Caption = "ต้นฉบับ"
DoCmd.OpenReport "Report_Bill", acViewNormal

DoCmd.OpenReport "Report_Bill", acViewDesign
Reports![report_bill]![ReportLabel].Caption = "สำเนา"
DoCmd.OpenReport "Report_Bill", acViewNormal



ยังไม่ทันพิมพ์ต้นฉบับ เหลือแสดงใบสุดท้ายเป็นสำเนา  ถ้าเราต้องการให้แสดงหน้าจอ 2 บิลคือต้นฉบับ+สำเนา  แล้วค่อยสั่งพิมพ์จะทำอย่างดีครับ

 

30 เม.ย. 62 , 09:15:46
ตอบกลับ #8

ปิ่นณรงค์

ผมเอา code จากกระทู้ตอบกลับ #1
DoCmd.OpenReport "Report_Bill", acViewDesign
Reports![report_bill]![ReportLabel].Caption = "ต้นฉบับ"
DoCmd.OpenReport "Report_Bill", acViewNormal

DoCmd.OpenReport "Report_Bill", acViewDesign
Reports![report_bill]![ReportLabel].Caption = "สำเนา"
DoCmd.OpenReport "Report_Bill", acViewNormal



ยังไม่ทันพิมพ์ต้นฉบับ เหลือแสดงใบสุดท้ายเป็นสำเนา  ถ้าเราต้องการให้แสดงหน้าจอ 2 บิลคือต้นฉบับ+สำเนา  แล้วค่อยสั่งพิมพ์จะทำอย่างดีครับ
ผมว่าวิธีง่ายๆ เลยนะครับ
คุณมีรายงาน 1 รายงานแล้ว ทำไมไม่ Copy มาตั้งชื่อใหม่โดยรายละเอียดข้างในเหมือนกันหมดเปลี่ยนแค่หัวของรายงาน

เช่น  1.มีรายงานชื่อ Report_Bill อยู่แล้ว กำหนดหัวว่า  ต้นฉบับ
      2.Copy รายงานนั้นมาวาง ตั้งชื่อ Report_Bill2 กำหนดหัวว่า สำเนา
แล้วกำหนด Event Onclick
DoCmd.OpenReport "Report_Bill", acViewNormal
DoCmd.OpenReport "Report_Bill", acViewReport

DoCmd.OpenReport "Report_Bill2", acViewNormal
DoCmd.OpenReport "Report_Bill2", acViewReport

เท่านี้ก็แสดง 2 หน้าปริ้นได้ ทั้ง 2 อัน ต้นฉบับและสำเนาแล้วคับ
« แก้ไขครั้งสุดท้าย: 30 เม.ย. 62 , 14:46:24 โดย ปิ่นณรงค์ »
:love: :grin:
 

30 เม.ย. 62 , 11:14:00
ตอบกลับ #9

kunlek

ขอบคุณครับ ทางออกนี้น่าจะดี  พอดีอยากจะลด report ลงครับ  ตอนนี้ก็ทำอย่างที่ อจ บอกล่ะครับ

 

30 เม.ย. 62 , 11:31:29
ตอบกลับ #10

ปิ่นณรงค์

ขอบคุณครับ ทางออกนี้น่าจะดี  พอดีอยากจะลด report ลงครับ  ตอนนี้ก็ทำอย่างที่ อจ บอกล่ะครับ
ถ้าเป็น Access Version 2007 ขึ้นไป น่าจะใช้โค้ดที่ผมโพสไปได้คับพี่ แต่ถ้าเวอร์ชั่นเก่ากว่าต้องลองให้อาจารย์ท่านอื่นๆ ดูนะครับ
:love: :grin:
 


บอร์ดเรียนรู้ Access สำหรับคนไทย


 

Sitemap 1 2 3 4 5