Results 1 to 6 of 6

Thread: Printing to word with a for loop

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    Printing to word with a for loop

    i have a program that prints to an MS word template. and it works perfect. the problem is this i have a list box in my app that i want to send all of the contents of the list box to the template i'm not so sure how i do this. i know that i will have to use a for loop(i think) but i was just wondering if some one could kinda point ina better direction.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    any one? can any one help me?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Can you do what you want with a single piece of text rather than a list?

    post the code & I'll alter it for you.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    i actually got it to work, the problem is now getting to move to a new line. but this my code, just to show you how i did it.
    VB Code:
    1. Dim sql As String
    2.     Dim PT As New ADODB.Recordset
    3.     sql = "SELECT Toolnumber FROM Machines WHERE MachNum= '" & MachID & "'"
    4.    
    5.     PT.Open sql, DBConn, adOpenDynamic, adLockOptimistic
    6.    
    7.     Do While Not PT.EOF
    8.         appWd.ActiveDocument.Bookmarks("Tool").Select
    9.         appWd.Selection.Text = PT!ToolNumber & ", "
    10.         appWd.Selection.MoveDown wdLine, 1
    11.         appWd.Selection.MoveLeft wdCharacter, 2
    12.         PT.MoveNext
    13.     Loop
    14.     PT.Close
    15.  
    16. problem:
    17.     Exit Function
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    cool. well try this for the new line bit (should be slightly faster too):
    VB Code:
    1. ...
    2. Dim strTemp as String
    3.     appWd.ActiveDocument.Bookmarks("Tool").Select
    4.     strTemp = ""
    5.     Do While Not PT.EOF
    6.         strTemp = strTemp & PT!ToolNumber & ", " & vbCr
    7.         PT.MoveNext
    8.     Loop
    9.     appWd.Selection.Text = strTemp
    10. ...
    I'm not sure if it is vbCr you need, if it isn't right try these instead:

    vbCrLf
    vbLf

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    that worked thanx a whole bunch dude. you are the man.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

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