Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,392 VB.NET Programmers. There are 1,402 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Printing address labels from VB.Net

 
Reply to this topicStart new topic

Printing address labels from VB.Net, retrieving rows from a datatable

GetThatFooty
post 24 Feb, 2008 - 11:12 PM
Post #1


New D.I.C Head

*
Joined: 2 Feb, 2008
Posts: 39



Hi.
I want to be able to print address labels using data from an access database to an A4 sheet of 21 labels (3 across x 7 down). Everything is working so far and I can get it to send one record at a time. but i don't know how to make it fill up the paper with 21 different names and addresses and go on to the next page. I'm really stuck now and could use some assistance. Thanks.

CODE

#Region " PrintDocument "
    Public Sub PrintDocument()
        Dim printer As New Printing()
        printer.PrinterFont = New Font("Verdana", 11)
        printer.TextToPrint = MailingnameTextBox.Text
        printer.TextToPrint = LastnameTextBox.Text
        printer.TextToPrint = StreetTextBox.Text
        printer.TextToPrint = CityTextBox.Text
        printer.TextToPrint = StateTextBox.Text
        printer.TextToPrint = ZipTextBox.Text
        printer.Print()
    End Sub
#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PrintDocument()
    End Sub


I'm using VB2008 but i'll take vb2005 help and convert it.

This post has been edited by GetThatFooty: 24 Feb, 2008 - 11:13 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


GetThatFooty
post 26 Feb, 2008 - 12:56 AM
Post #2


New D.I.C Head

*
Joined: 2 Feb, 2008
Posts: 39

No one can help on this one?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

PsychoCoder
post 26 Feb, 2008 - 01:02 AM
Post #3


ToCode || !ToCode

Group Icon
Joined: 26 Jul, 2007
Posts: 5,858

Well that may be a bit more complex than the class I wrote for the tutorial on printing in VB.Net. What you're wanting will take a bit more complex code as you'll have to define your 7 x 3 matrix, its size, margins and such. Ill have to look further into this one.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

GetThatFooty
post 26 Feb, 2008 - 09:52 AM
Post #4


New D.I.C Head

*
Joined: 2 Feb, 2008
Posts: 39

QUOTE(PsychoCoder @ 26 Feb, 2008 - 01:02 AM) *

Well that may be a bit more complex than the class I wrote for the tutorial on printing in VB.Net. What you're wanting will take a bit more complex code as you'll have to define your 7 x 3 matrix, its size, margins and such. Ill have to look further into this one.


Would it be easier to use a template like this one and export a file into word?
Avery Label Template

I would rather use this template than the 7x3

1" x 2 5/8"
10x3

Thanks psychocoder

Would this be what i'm trying to accomplish or help me in any way?
Datagrid Print

This post has been edited by GetThatFooty: 26 Feb, 2008 - 10:04 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

GetThatFooty
post 27 Feb, 2008 - 02:54 PM
Post #5


New D.I.C Head

*
Joined: 2 Feb, 2008
Posts: 39

Hey guys I could still use some help with this one.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

jayman9
post 27 Feb, 2008 - 03:36 PM
Post #6


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 5,566

Using the template loaded into Word is by far the easiest solution to your problem. Otherwise you will need to replicate the data across the page manually to get the results you want, this could be rather cumbersome.

You can find info on how to use the MS Word template in your application here.

It shows you how to apply it to the template towards the bottom.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

GetThatFooty
post 27 Feb, 2008 - 08:12 PM
Post #7


New D.I.C Head

*
Joined: 2 Feb, 2008
Posts: 39

cool thanks i'll give that a shot
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

GetThatFooty
post 28 Feb, 2008 - 04:42 PM
Post #8


New D.I.C Head

*
Joined: 2 Feb, 2008
Posts: 39

ok. i got it to open word but i'm getting an error when i try to get it to apply the template. it's probably something stupid. The error i'm getting is:

Word was unable to read this document. It may be corrupt. Try one or more of the following: * Open and Repair the file. * Open the file with the Text Recovery converter.

I know it is not corrupt because it can be opened if i browse to it and open it manually.
The only thing i noticed that was odd was the file extension is .dotm instead of .dot

CODE

Private Sub PrintBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintBtn.Click
        Dim oWord As Word.Application
        Dim oDoc As Word.Document
oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add
        oWord.Documents.Add("<C:\Users\Ryan\AppData\Roaming\Microsoft\Templates>\Mailing Labels.dotm")     <-Error
End Sub


i am also having problems with getting word to insert names and addresses from my access database. any ideas on that?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

creativesoul
post 29 Apr, 2008 - 07:31 AM
Post #9


New D.I.C Head

*
Joined: 29 Apr, 2008
Posts: 2

Hi GetThatFooty,

Still having troubles?

Why not build your own word table?
Try something like this

CODE
private sub createWordDoc
objWordApp = New Word.Application
objWordApp.Visible = true ' true or false
objDoc = New Word.Document

'Create a new Word document and add some text to it.
objDoc = objWordApp.Documents.Add
dim TableData As ArrayList ' fill arraylist with your data

InsertDataTable(objDoc, TableData )

dim Printername as striing = "your printername"

try

    If Printername <> "" Then
                    objWordApp.WordBasic.FilePrintSetup(Printer:=Printername, DoNotSetAsSysDefault:=1)
                    objWordApp.PrintOut()
                End If

Catch ex As Exception

Finally
  objWordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
  objWordApp.Quit()
  objWordApp = Nothing

   End Try

end sub


and to put your data in the doc something like this

CODE

    Private Sub InsertDataTable(ByVal doc As Word.Document, ByVal TableData As ArrayList)
        With doc
         .Range.InsertParagraphAfter()
         .Range.Tables.Add(.Paragraphs.Item(.Paragraphs.Count).Range, 2, 5, 1, 1)

            For n As Integer = 0 To TableData.Count -1
                .Tables.Item(.Tables.Count).Rows.Add()
                Dim s As String() = TableData(i).ToString.Split("|")
                i += 1
                .Tables.Item(.Tables.Count).Cell(n, 1).Range.Text = s(0)
                .Tables.Item(.Tables.Count).Cell(n, 2).Range.Text = s(1)
                .Tables.Item(.Tables.Count).Cell(n, 3).Range.Text = s(2)
                .Tables.Item(.Tables.Count).Cell(n, 4).Range.Text = s(3)
                .Tables.Item(.Tables.Count).Cell(n, 5).Range.Text = s(5)
                .Tables.Item(.Tables.Count).AllowAutoFit = True

            Next
        End With
    End Sub


hope this helps
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

TheWhiteSeal
post 9 May, 2008 - 04:46 AM
Post #10


New D.I.C Head

*
Joined: 9 May, 2008
Posts: 1

Hi all,

On the subject of printing address labels i would have to admit i never really had much luck with getting the printed with my label printer. It seemed as though i was spending more time messing around with the printer than printing out labels. In the end i decided to give up on the whole DIY approach and i found a british labels company who printed my address labels for me, it saved me so much hassle.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 05:09AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month