การพิมพ์ Label ตามจำนวนใบที่ต้องการ
กระทู้เก่าบอร์ด อ.Yeadram

 3,334   14
URL.หัวข้อ / URL
การพิมพ์ Label ตามจำนวนใบที่ต้องการ

พอดีมีข้อมูลใน Table หรือ iQuery แล้วจะสร้าง Report Label ตามจำนวนที่ tabel กำหนด เช่น
ชื่อ                  ที่อยู่                 เบอร์             จำนวนLabel
ธีระ                 เลย            084-5566781           100 ดวง
ชนะ              นครปฐม       084-5562214             50 ดวง
กสิน              เพชรบุรี        085- 5562214           80 ดวง

โดยจะออก Report เพียงครั้งเดียวพร้อมสั่งพิมพ์ตามจำนวนที่กำหนดใน Table หรือ Query

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

1 @R17157
ผมว่าต้องไปสร้างเทเบิลชั่วคราวอีกเทเบิล ให้มีฟิลด์เก็บข้อมูลที่ต้องการพิมพ์ออกลาเบล โปรแกรมต้องอ่านจากเทเบิลหรือคิวรี่หลัก แล้วไปสร้างเป็นเรคอร์ดซ้ำๆกันเท่ากับจำนวนลาเบลที่ต้องการลงในเทเบิลชั่วคราว การพิมพ์ก็พิมพ์จากเทเบิลชั่วคราวนี้แทน อย่าลืมลบเรคอร์ดในเทเบิลชั่วคราวให้หมดก่อนการการสร้างเรคอร์ดครั้งใหม่ด้วย
2 @R17161
พอจะมีวิธีสร้าง คิวรี่ ที่ให้เรคอร์ดซ้ำกันตามจำนวน ดวงที่ระบุใหม ไม่รู้จะวนลูปยังไง
3 @R17162
ในทางทฤษฏีมี แต่ทางปฏิบัติจะไหวมั๊ยก็ลองพิจารณาดูนะครับ คือให้สร้างเทเบิลอีกเทเบิล สมมุติชื่อ T เทเบิลมีเพียงฟิลด์เดียว สมมุติชื่อ F เทเบิล T ไม่ต้องมี primarykey แต่ให้สร้าง index ไว้ที่ฟิลด์ F และต้องไม่เป็น unique index ด้วย

ให้ป้อนค่า 1 ลงในฟิลด์ F เพียง 1 เรคอร์ด
ให้ป้อนค่า 2 ลงในฟิลด์ F ทั้งหมด 2 เรคอร์ดซ้ำกัน
ให้ป้อนค่า 3 ลงในฟิลด์ F ทั้งหมด 3 เรคอร์ดซ้ำกัน
...
...
...
ทำไปเรื่อยๆจนเท่ากับจำนวนเลขลาเบลสูงสุดที่มี อย่างตัวอย่างที่ให้มาคือ 100 (ลาเบล) ก็คือ ป้อนค่า 100 ลงในฟิลด์ F ทั้งหมด 100 เรคอร์ดซ้ำกัน

จุดนี้แหล่ะครับที่เป็นตัวบอกว่าทำได้จริงในทางปฏิบัติหรือไม่ ถ้าไม่รู้ค่าสูงสุดก็ทำไม่ได้ครับ หรือแม้รู้ แต่จะมาป้อนไหวหรือไม่ ในกรณีสูงสุดคือ 100 คุณต้องป้อนรวมทั้งหมดแล้ว 640 เรคอร์ด (ถ้าคำนวนไม่ผิดนะ)

จากนั้นสร้างคิวรี่ Q ให้ทำ inner join ระหว่างฟิลด์จำนวนลาเบลในเทเบิลหลัก กับ ฟิลด์ F ในเทเบิล T เท่านี้คุณก็จะได้ จำนวนเรคอร์ดในเทเบิลหลักออกมาซ้ำๆเท่ากับจำนวนดวงของลาเบลแล้วครับ

แล้วเทเบิล T ไม่ต้องลบเรคอร์ดทิ้งนะครับ ต้องใช้ตลอดไปครับ
4 @R17163
ผิดแล้ว จะเป็นห้าพันกว่าเรคอร์ด ไม่ใช่ 640 เรคอร์ด
5 @R17168
docmd.PrintOut(PrintRange, PageFrom, PageTo, PrintQuality, Copies, CollateCopies)
แล้วให้มันรับค่าจำนวน copies ได้มั้ยครับ อ.สันติสุข
6 @R17174
มันจะเป็นจำนวนเท่าของกระดาษหน่ะครับ ไม่ใช่จำนวนเท่าของเรคอร์ด เขียนโปรแกรมอย่างที่ผมตอบอันแรกสุดแหล่ะครับ ง่ายสุดแล้ว
7 @R17178
ค้นมาเผื่อครับ
A simpler and code-free solution uses a query with a record for each label. To do this, you need a table containing a record from 1 to the largest number of labels you could ever need for any one record.

Create a new table, containing just one field named CountID, of type Number (Long Integer). Mark the field as the primary key (toolbar icon). Save the table as tblCount.
Enter the records into this table manually, or use the function below to enter 1000 records instantly.
Create a query that contains both this table and the table containing your data. If you see any line joining the two tables, delete it. It is the lack of a join that gives you a record for each combination. This is known as a Cartesian Product.
Drag tblCount.CountID into the query's output grid. Use the Criteria row beneath this field to specify the number of labels. For example, if your table has a field named Quantity, enter:
   <= [Quantity]
or if you always want 16 labels, enter:
   <= 16
Include the other fields you want, and save the query. Use it as the RecordSource for your label report.
Optional: To print "1 of 5" on the label, add a text box to the report, with this in its ControlSource:
   =[CountID] & " of " & [Quantity]
Ensure the Name of this text box is different from your field names (e.g. it can't be named "CountID" or "Quantity"). To ensure the labels print in the correct order, include CountID in the report's Sorting And Grouping dialog.
That's it.

Here's the function that will enter 1000 records in the counter table. Paste it into a module. Then press Ctrl+G to open the Immediate window, and enter:
   ? MakeData()

Function MakeData()
    'Purpose:   Create the records for a counter table.
    Dim db As Database                  'Current database.
    Dim lng As Long                     'Loop controller.
    Dim rs As DAO.Recordset             'Table to append to.
    Const conMaxRecords As Long = 1000 'Number of records you want.

    Set db = DBEngine(0)(0)
    Set rs = db.OpenRecordset("tblCount", dbOpenDynaset, dbAppendOnly)
    With rs
        For lng = 1 To conMaxRecords
            .AddNew
               !CountID = lng
            .Update
        Next
    End With
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    MakeData = "Records created."
End Function
(The function requires the DAO library: more information).
8 @R17184
ตอนนี้แก้ปัญหา ตามที่อาจารย์ สันติสุข แนะนำก่อน ส่วนของอาจารย์ ศักดาน่าน
ขอศึกษาหน่อย ไม่ค่อยถนัด VB -*- ไม่เข้าใจว่ามันจะวางจะใส่ตอนไหน อิอิ
ขอบคุณมากนะครับ สำหรับคำแนะนำและชีแนะ
9 @R17186
คิดได้อีกหน่อย เพื่อที่จะได้ไม่ต้องป้อนตัวเลขลงเทเบิล T เยอะ ก็คือกำหนดว่า ต่อ 1 เรคอร์ดของรายชื่อ ให้ใส่ตัวเลขจำนวนลาเบลได้ไม่เกิน 10 ดวง ถ้าต้องการมากกว่านั้นก็ต้องเป็นอีก 1 เรคอร์ด เช่น นาย ก. ต้องการ 35 ดวง ก็ต้องป้อน 4 เรคอร์ด เป็น

นาย ก.    30 ดวง
นาย ก.    30 ดวง
นาย ก.    30 ดวง
นาย ก.    5 ดวง

ถ้าทำได้ตามนี้ เทเบิล T ก็ป้อนแค่

ป้อนค่า 1 ลงในฟิลด์ F เพียง 1 เรคอร์ด
ป้อนค่า 2 ลงในฟิลด์ F ทั้งหมด 2 เรคอร์ดซ้ำกัน
ป้อนค่า 3 ลงในฟิลด์ F ทั้งหมด 3 เรคอร์ดซ้ำกัน
...
...
...
ป้อนค่า 10 ลงในฟิลด์ F เพียง 10 เรคอร์ด
10 @R17191
เอาใหม่ๆๆ คิดว่าได้แล้ว เทเบิล T ไม่ต้องมีค่าซ้ำแล้ว ถ้าสูงสุดคือ 100 ลาเบล ก็สร้าง 100 เรคอร์ด มีค่า 1,2,3,... ไปเรื่อยๆ จากนั้นก็สร้างคิวรี่ตามนี้ (สมมุติข้อมูลหลักอยู่ในเทเบิล A, ฟิลด์จำนวนลาเบลคือ N)

select A.* from A, T where A.N >= T.F order by ฟิลด์ชื่อ

แค่นี้ครับ
11 @R17192
แก้ไขเป็น

select A.* from A, T where A.N >= T.F order by A.ฟิลด์ชื่อ
12 @R17193
เย้ๆๆ ได้แล้วครับอาจาร์ยสุดยอดเลย แก้ปัญหามานาน ขอบคุณมากครับ
13 @R17207
ช่วยอัพโหลดไฟล์มาให้ศึกษาบ้างได้ไหม
14 @R17222


table T ฟิล F คือรันจำนวน 1.2.3.4.5......500
table A คือข้อมุล ฟิว N คือจำนวนดวงที่ต้องการแล้วนำ คอรี่ไปออก Report
กด โหมด Sql ก็จะได้ตามที่อาจาร์ยบอก

^^
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.1952s