Hello
I want to print the multiple copies of data report as shown in the attached picture, its printing only printing only one.
I have created the text box in the form to provide the number of copies named as txtcopies. plz check and resolve
Here is the full coding of that form
Code:
Option Explicit
Private Sub btnprnt_Click()
Dim qty As Integer
Dim A As Integer
qty = txtcopies.Text
On Error Resume Next
'Check if the barcode field is blank
If txtbarcodes.Text = "" Then
MsgBox "Please enter the barcode", vbInformation, "Barcode Error"
txtbarcodes.SetFocus
Exit Sub
End If
Set ac = New ADODB.Connection
Set ar = New ADODB.Recordset
Call openDB
ac.Open strConek
With ar
SQL = "Select *From tblproduct Where Barcode='" & txtbarcodes.Text & "'"
.Open SQL, strConek, adOpenStatic, adLockOptimistic
If .RecordCount >= 1 Then
If !Barcode = txtbarcodes.Text Then
SQL = "Select *From tblproduct where Barcode= '" & txtbarcodes.Text & "'"
DE.rsproduct.Open SQL
With printbarcode
.Sections("Section1").Controls.Item("txtDescription").Caption = !Description
.Sections("Section1").Controls.Item("txtUnitPrice").Caption = !UnitPrice
Set .Sections("Section1").Controls.Item("Image1").Picture = LoadPicture(App.Path & "\Barcodes\" & txtbarcodes & ".jpg")
For A = 1 To qty
Call printbarcode.PrintReport(False, rptRangeAllPages)
Next A
DE.rsproduct.Close
End With
Else
MsgBox "Barcode not found", vbInformation, "Record not found"
End If
Else
MsgBox "No product exist in database", vbInformation, "Record not found"
End If
.Close
End With
End Sub
I did not see where you were setting the qty before but now I do. At a glance what is there looks like it should work but then again I use a different report tool and have never used the one built into VB.
I would think that you should be able to specify the number of copies when it is sent to the printer.
But you should see this when you step through the program ONE LINE AT A TIME
The variable qty is obviously set correctly and you can see this in debug mode - I suspect there is an error in the called routine which aborts the process somehow
This question was cross posted on VBForums where there has been a bit more info uncovered. As far as I can tell rather than printing multiple copies of the report what he was to do is print a variable number of barcode labels on the same page. Calling print in a loop will not solve this issue unless he uses a roll of labels on a label printer where each label counts as a page. To do this on a full size page the report will have to be designed to print a page full of labels with the same value or he will have to write code behind the report to populate the values. Otherwise would have to abandon the report and use the printer object setting current x and y values to print in the proper locations.
When generating barcodes there are a few things to consider. What type of barcode do you need, what kind of printer are you using.
In many cases a font will do the job, in other cases it is best to use the native printer language and in other cases may be best to use a 3rd party library or control
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.