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

เริ่มโดย kunlek, 26 เม.ย 19 , 21:31:30

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

kunlek

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

ปิ่นณรงค์

อ้างถึงจาก: kunlek ใน 26 เม.ย 19 , 21:31:30
สร้างปุ่ม command ไว้ที่ toolbar กด click แสดง report_bill ทั้ง ต้นฉบับ กับสำเนา(เพราะไม่ได้ printer หัวเข็มจึงต้องพิมพ์ที่2บิล)

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

วิธีการ 1.สร้าง Lable กำหนดชื่อ Lable เช่น ReportLabel ตัวรายงานชื่อ  Report_Bill
        2.ที่ปุ่ม Command Event Onclick ใส่โค้ดไปว่า
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 ขึ้นมา
ใส่โค้ดนี้เข้าไป
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 ขึ้นมา ใส่โค้ดนี้เข้าไป

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


ตัวอย่างด้านล่าง
:love: :grin:
  •  

kunlek

  •  

ปิ่นณรงค์

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

kunlek

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

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
  •  

ปิ่นณรงค์

ลองแก้เป็น
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:
:love: :grin:
  •  

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 บิลคือต้นฉบับ+สำเนา  แล้วค่อยสั่งพิมพ์จะทำอย่างดีครับ
  •  

ปิ่นณรงค์

อ้างถึงจาก: kunlek ใน 30 เม.ย 19 , 08:55:10
ผมเอา 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 อัน ต้นฉบับและสำเนาแล้วคับ
:love: :grin:
  •  

kunlek

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

ปิ่นณรงค์

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