Printing Labels

divjoy

Well-known member
Joined
Aug 25, 2013
Messages
159
Programming Experience
1-3
Hi, I am trying to develop a Win form app to print a repeating label on MS Word Document, 2 x 8 label page (16 Labels).

Not sure what is the best way to go, I was using ms word.Application Word.document to display the labels

I'm having difficulty printing the second label as I am adding space to align to the second label and then repeat 8 times down the page...
My second label is out of alignment as it depends on the size of characters on the left label!
Bummer I would prefer to use tabs but cant get them to work for me!

The 16 labels fit on the page well though!

Print Labels:
Private Sub CreateLabelDocument(ByVal strClientID As String, ByVal strNameDOB As String, ByVal strAddress As String, ByVal strCounty As String)
        Dim objWord As Word.Application
        Dim objDoc As Word.Document
        Dim strName As String = "J. Smith"
        Dim x, y As Integer
        ' MsgBox(PatID)
        Try

            If strNameDOB.Length > 15 Then
                objWord = CreateObject("Word.Application")
                objWord.Visible = True
                objDoc = objWord.Documents.Add
                objDoc.PageSetup.TopMargin = 30

                'objDoc.Format.BeforeAutoSpacing = False
                'objDoc.Format.BeforeSpacing = 10
                'objDoc.Format.AfterAutoSpacing = False
                'objDoc.Format.AfterSpacing = 10
                Dim objPara As Word.Paragraph
                For x = 1 To 8
                    'Print ClientID 
                    y = 90 - strClientID.Length
                    objPara = objDoc.Content.Paragraphs.Add
                    objPara.Range.Text = vbCrLf & strClientID.PadRight(y) & strClientID
                    objPara.Range.Font.Bold = False
                    objPara.Range.Font.Underline = False
                    objPara.Range.Font.Size = 10
                    objPara.Range.Font.Name = "Arial"
                    objPara.Format.SpaceAfter = 1
                    ' objPara.LineSpacing = 10
                    objPara.Range.InsertParagraphAfter()

                    'Print Name
                    y = 90 - strNameDOB.Length
                    objPara = objDoc.Content.Paragraphs.Add
                    objPara.Range.Text = strNameDOB.PadRight(y + 4) & strNameDOB
                    objPara.Range.Font.Bold = False
                    objPara.Range.Font.Underline = False
                    objPara.Range.Font.Size = 10
                    objPara.Range.Font.Name = "Arial"
                    objPara.Format.SpaceAfter = 1
                    ' objPara.LineSpacing = 10
                    objPara.Range.InsertParagraphAfter()

                    'Print Address
                    y = 90 - strAddress.Length
                    objPara = objDoc.Content.Paragraphs.Add
                    objPara.Range.Text = strAddress.PadRight(y) & strAddress
                    objPara.Range.Font.Bold = False
                    objPara.Range.Font.Underline = False
                    objPara.Range.Font.Size = 10
                    objPara.Range.Font.Name = "Arial"
                    objPara.Format.SpaceAfter = 1
                    ' objPara.LineSpacing = 10
                    objPara.Range.InsertParagraphAfter()

                    'Print Country & Postcode
                    y = 90 - strCounty.Length
                    objPara = objDoc.Content.Paragraphs.Add
                    objPara.Range.Text = strCountry.PadRight(y) & strCountry
                    objPara.Range.Font.Bold = False
                    objPara.Range.Font.Underline = False
                    objPara.Range.Font.Size = 10
                    objPara.Range.Font.Name = "Arial"
                    objPara.Format.SpaceAfter = 1
                    ' objPara.LineSpacing = 10
                    objPara.Range.InsertParagraphAfter()

                    If x < 8 Then 'Not for last row!!!
                        'Move Down to Next label
                        objPara = objDoc.Content.Paragraphs.Add
                        objPara.Range.Text = vbCrLf '& vbCrLf 
                        objPara.Range.Font.Bold = False
                        objPara.Range.Font.Underline = False
                        objPara.Range.Font.Size = 10
                        objPara.Range.Font.Name = "Arial"
                        objPara.Format.SpaceAfter = 0
                        ' objPara.LineSpacing = 10
                        objPara.Range.InsertParagraphAfter()
                    End If
                Next x

            Else
                MessageBox.Show("Labels cant be printed as no client details found!", strTitle)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, strTitle)
        End Try

    End Sub

Im using Q Connect Code NO: KF01132 A4 labels.
I'm open to any other suggestions too?

Thanks

Gerry
 
Last edited:
Top Bottom