CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2012
    Posts
    2

    Data Report urgent help

    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
    Attached Images Attached Images  

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Data Report urgent help

    You are not setting the qty

    you should also get rid of that on error resume next.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    May 2012
    Posts
    2

    Re: Data Report urgent help

    any solution

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Data Report urgent help

    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.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Data Report urgent help

    As DataMiser said, remove the On Error Resume Next and an error might come up and explain to you the reason why the loop would not work.

  6. #6
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,900

    Re: Data Report urgent help

    Why aren't you stepping the program through step by step in debug mode and looking at the change of variables ? (Its not a big program)

    The error may be taking place in

    Code:
    Call printbarcode.PrintReport(False, rptRangeAllPages)
    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

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Data Report urgent help

    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.
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Jun 2014
    Posts
    1

    Re: Data Report urgent help

    Just looking for a barcode generator, have you guys ever tried this? That would be so great if someone could shed some light on this!

  9. #9
    Join Date
    Nov 2014
    Posts
    3

    Re: Data Report urgent help

    Do you want to print and generate barcode label?I think using a barcode generator will make things easier.

  10. #10
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Data Report urgent help

    That generator is C#

    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
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured