print from a access list box in form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buddyr
    New Member
    • Apr 2007
    • 105

    print from a access list box in form

    I have two listboxes on a microsoft access form. I can click a button to move data from listbox1 to listbox2.

    Can I print the data in listbox2 formatted with a barcode font.
    I guess first can I print the data in listbox2?

    Thank you
  • JustJim
    Recognized Expert Contributor
    • May 2007
    • 407

    #2
    Originally posted by buddyr
    I have two listboxes on a microsoft access form. I can click a button to move data from listbox1 to listbox2.

    Can I print the data in listbox2 formatted with a barcode font.
    I guess first can I print the data in listbox2?

    Thank you
    Pulling the data out of a list box is no trivial matter (I've done it before and I'll go and refresh my memory shortly).

    What you will need to do is create a report with a "can grow" text box on it. Set the text box to use your barcode font.

    Then you place a button on your form and put code in its "On Click" event to strip the data from the list box and put it into the text box on the report, probably plugging a couple of CR/LF between each one.

    I'll be back shortly with the list box code.

    Jim

    Comment

    • JustJim
      Recognized Expert Contributor
      • May 2007
      • 407

      #3
      Originally posted by buddyr
      I have two listboxes on a microsoft access form. I can click a button to move data from listbox1 to listbox2.

      Can I print the data in listbox2 formatted with a barcode font.
      I guess first can I print the data in listbox2?

      Thank you
      OK, here's a solution that I'm not 100% happy with....

      Make a report, call it rptPrintData
      Put a text box on the detail section, call that txtData
      Set the font for that text box to your barcode font, and the font size to whatever you need
      Set the text box 'Can Grow' property to Yes

      Put the following code in the On Format event of the Detail section of the report

      [CODE=vb]Private Sub Detail_Format(C ancel As Integer, FormatCount As Integer)
      Me.txtData.Valu e = Me.OpenArgs
      End Sub[/CODE]

      Close and save your report

      Open the form with the list boxes in design mode
      Change the Multi Select property of your ListBox2 to Extended (this is in the Other tab of the properties dialog)
      Add a button called btnPrint and add the following code to its On Click event

      [CODE=vb]Private Sub btnPrint_Click( )
      Dim varSelect As Variant
      Dim strDataString As String

      For Each varSelect In Me.Controls("ls tData").ItemsSe lected
      strDataString = strDataString & Me.Controls("ls tData").ItemDat a(varSelect) & Chr(32)
      Next varSelect

      DoCmd.OpenRepor t "rptPrintDa ta", acViewPreview, , , , strDataString

      End Sub
      [/CODE]

      (Here's the bit I'm not happy with. I wanted to add Chr(13) to the end of each item in strDataString as it was constructed, but Chr(13) doesn't cause a CR in a text box so I just added a space Chr(32) so you have to size the text box on the report just right to force a soft CR in the display of the data in the text box.)

      (As an aside, when you enter text from the keyboard into a text box, and you want a new line, you press <Alt><Enter>, but I can't figger out how to put this into a character string)

      OK, now with the report closed and the form open, select everything in the list box that you want to print and click the button. Check the report and resize the text box as required.

      The good news is, you could use this on ListBox1 and do away with ListBox2 altogether.

      Enjoy.

      Comment

      • buddyr
        New Member
        • Apr 2007
        • 105

        #4
        thank you - sorry to take awhile to respond- away for easter

        Comment

        • JustJim
          Recognized Expert Contributor
          • May 2007
          • 407

          #5
          Originally posted by buddyr
          thank you - sorry to take awhile to respond- away for easter
          No worries.

          If you change the & Chr(32) to & vbNewLine or optionally & Chr(13) & Chr(10) you will get the proper look without the fiddly re-sizing of the text box.

          (Thanks to MissingLinq for that information)

          Jim

          Comment

          Working...