Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make many copies of label in a report 1

Status
Not open for further replies.

Yosua

Programmer
Aug 23, 2011
25
Hi,
I have a simple product table
Product_Id
Product_Type
Product_Name
Product_Stock

The label (about 5cm x 3cm)
Product_id (in Barcode)
Product Type

I'm confused, how can I make a report consist of many same product label in report as much as the product stock automatically?
So when I add 30 stock it print the label 30 times, it multiplies horizontally and vertically.

Thanks for any feedback and solution
Yosua


 
One way to do this would be to create a cursor that contains the required number of records for each product.

Something like this:

Code:
CREATE CURSOR ProdLabels (Product_ID I, Product_Type C(16))
SELECT ProductTable
SCAN
  FOR lnI = 1 TO Product_stock
    INSERT INTO ProdLabels ;
      VALUES(ProductTable.Product_ID, ProductTable.Product_type)
  ENDFOR
ENDSCAN

Then run your labels against that cursor.

I haven't tried to test this code, so can't be sure it's correct, but it should give you the general idea.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike thanks for your quick reply, sorry I don't understand the last half of your code, can you en-light me the logic?
And how can I multiply it horizontally and vertically in the report?

Thanks
 
Yosua,

I'm not sure what you mean by "the last half of your code". However, I will try to explain.

The aim of the code is to create a cursor, in which there is one record for each label that is to be printed. So, if product A has a stock of 10 units, the cursor will have ten records for product A, and you'll get ten labels for that product. And so on for product B, etc.

It does that by looping through the records in the original products table. For each record, it runs another loop, based on the number of units in stock. Each time round that inner loop, it inserts a record into the cursor.

As far as multiplying horizontally and vertically is concerned, you don't have to worry about that. You just need to create a label rather than a report.

To do that, type CREATE LABEL in the command window. You will be prompted to choose your label size. After you've done that, you'll be in the designer, which works in almost the same was as the report designer.

After you've saved your label in the designer, you can print it by running a LABEL FORM command (which is similar to the REPORT FORM command).

I hope this makes sense.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thank you very much, Mike
I'll try your solution
 
Mike your code is working!
Which part of the code I need to change if I use MySQL Database?
Thanks a lot
 
Glad to hear it works, Yosua.

As far as MySQL is concerned, I assume you mean that the Products table is in MySQL? If so, use SQLEXEC() to get the contents of that table into a local cursor (I know from your other thread that you know how to do that). Then use that cursor in place of the original Products table. Everything else should be the same.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks, and sorry if for other thread :)
Because I think it's a different topic.
Should I place the cursor in the field or in
data environment>code?
 
It's OK to make it a separate thread, because it is really a different question.

Basically, you need to do something like this:

Code:
CREATE CURSOR ProdLabels (Product_ID I, Product_Type C(16))

* Put the SQLEXEC() here. It should retrieve your product
* data from MySQL, and return it in a cursor named ProductTable.

SELECT ProductTable
SCAN
  FOR lnI = 1 TO Product_stock
    INSERT INTO ProdLabels ;
      VALUES(ProductTable.Product_ID, ProductTable.Product_type)
  ENDFOR
ENDSCAN

In other words, instead of using a DBF named ProductTable, you use SQLEXEC() to create a cursor named ProductTable. Everything else is the same.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top