Results 1 to 5 of 5

Thread: Word does not print

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    62

    Word does not print

    Hello to all,

    word2000 and vb6

    When I run this in debug mode, I get me letters.
    If I run this in RUNTIME mode, I get no letters.

    here is where I think it does not work


    objWordDocuments.Application.PrintOut



    Do anyone have any idea what is going on here.

    I spend a week on this but could not figured it out.

    thanks a bunch.

    Private Sub CmdCustomerLetter_Click()
    call InitilizeWord
    call CheckedBoxSelected
    end sub

    Private Sub InitilizeWord()

    'CREATE MS WORD APPLICATION OBJECT.
    If TypeName(objWordApplication) = "Application" Then
    Set objWordApplication = GetObject(, "Word.Application")
    Else
    Set objWordApplication = CreateObject("Word.Application")
    End If
    Set objWordDocuments = objWordApplication.Documents
    Exit Sub
    end sub

    Private Sub CheckedBoxSelected()
    Dim k As Integer


    If Me.LvwCust.ListItems.Count > 1 Then
    For k = 1 To Me.LvwCust.ListItems.Count
    If Me.LvwCust.ListItems.Item(k).Checked Then
    Call GetBkMark(k)
    End If
    Next k
    End If
    End Sub

    Private Sub GetBkMark(ByVal SelItemIndex As Integer)
    '*************************************************************************************************** *****************


    Dim strPathName As String
    Dim strFileName As String
    Dim j As Integer
    Dim objTemplate As Word.Document
    Dim k As Integer


    strPathName = App.Path & "\"
    strFileName = "Customer.dot"

    Set objWordDocuments = objWordApplication.Documents
    'Set objTemplate = objWordDocuments.Add(strPathName & strFileName, True, wdNewBlankDocument, True)

    For k = 1 To Me.LvwCust.ListItems.Count
    If k = SelItemIndex Then
    Set objTemplate = objWordDocuments.Add(strPathName & strFileName, True, wdNewBlankDocument, True)
    With objTemplate

    If .Bookmarks.Exists("CustName") Then
    .Bookmarks("CustName").Range.text =Trim(Me.LvwCust.ListItems.Item(k).SubItems(2)) & " " & Trim(Me.LvwCust.ListItems.Item(k).SubItems(1)))
    End If
    'ADDRESS
    If .Bookmarks.Exists("Address") Then
    .Bookmarks("Address").Range.text = Trim(Me.LvwCust.ListItems.Item(k).SubItems(5)))
    End If
    objWordDocuments.Application.PrintOut
    End With
    End If
    Next k
    End Sub

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Not a reply, just to VB things better...

    VB Code:
    1. Private Sub CmdCustomerLetter_Click()
    2. call InitilizeWord
    3. call CheckedBoxSelected
    4. end sub
    5.  
    6. Private Sub InitilizeWord()
    7.  
    8. 'CREATE MS WORD APPLICATION OBJECT.
    9. If TypeName(objWordApplication) = "Application" Then
    10. Set objWordApplication = GetObject(, "Word.Application")
    11. Else
    12. Set objWordApplication = CreateObject("Word.Application")
    13. End If
    14. Set objWordDocuments = objWordApplication.Documents
    15. Exit Sub
    16. end sub
    17.  
    18. Private Sub CheckedBoxSelected()
    19. Dim k As Integer
    20.  
    21.  
    22. If Me.LvwCust.ListItems.Count > 1 Then
    23. For k = 1 To Me.LvwCust.ListItems.Count
    24. If Me.LvwCust.ListItems.Item(k).Checked Then
    25. Call GetBkMark(k)
    26. End If
    27. Next k
    28. End If
    29. End Sub
    30.  
    31. Private Sub GetBkMark(ByVal SelItemIndex As Integer)
    32. '***************************************************************************************************
    33. *****************
    34.  
    35.  
    36. Dim strPathName As String
    37. Dim strFileName As String
    38. Dim j As Integer
    39. Dim objTemplate As Word.Document
    40. Dim k As Integer
    41.  
    42.  
    43. strPathName = App.Path & "\"
    44. strFileName = "Customer.dot"
    45.  
    46. Set objWordDocuments = objWordApplication.Documents
    47. 'Set objTemplate = objWordDocuments.Add(strPathName & strFileName, True, wdNewBlankDocument, True)
    48.  
    49. For k = 1 To Me.LvwCust.ListItems.Count
    50. If k = SelItemIndex Then
    51. Set objTemplate = objWordDocuments.Add(strPathName & strFileName, True, wdNewBlankDocument, True)
    52. With objTemplate
    53.  
    54. If .Bookmarks.Exists("CustName") Then
    55. .Bookmarks("CustName").Range.text =Trim(Me.LvwCust.ListItems.Item(k).SubItems(2)) & " " & Trim(Me.LvwCust.ListItems.Item(k).SubItems(1)))
    56. End If
    57. 'ADDRESS
    58. If .Bookmarks.Exists("Address") Then
    59. .Bookmarks("Address").Range.text = Trim(Me.LvwCust.ListItems.Item(k).SubItems(5)))
    60. End If
    61. objWordDocuments.Application.PrintOut
    62. End With
    63. End If
    64. Next k
    65.  
    66. End Sub
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Every time I have seen someone use the .PrintOut command with word, I have seen more parameters. For example:

    Obj.PrintOut Range:=wdPrintFromTo, From:=”1”. To:=”3”
    Obj.PrintOut copies:=1, collate:=True, Background:=False

    In these cases OBJ is the DOCUMENT, not the collection of documents or the application. I.e. it should be ObjTemplate in your example.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    62
    Hi JordanChris,

    I have an error here on this line From:=”1”. To:=”3”
    what does it relally mean.

    Obj.PrintOut Range:=wdPrintFromTo, From:=”1”. To:=”3”

    Also, is there a way I can output each document to the screen for user to edit the document if they wanted to and then print them out.


    thanks

  5. #5
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Sorry. That code was for use in the VBA of Word, rather than in VB calling word - slightly different syntax.

    Yes, you can show the document to the user - but you might not then be able to prnit t automatically, as you wont know when the user has finished looking at it and its ready to print.

    Take a look at the
    <Object>.Visible = True
    property. This might need to be set on the application (objWordApplication) or on the document (objTemplate).

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