Finally an easy way to print to text, or word - InfoPath Dev
in

InfoPath Dev

Finally an easy way to print to text, or word

Last post 06-04-2007 10:10 AM by Matt Faus. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 09-12-2006 02:28 PM

    Finally an easy way to print to text, or word

    Ive spent the past couple weeks kinda seeing what was out there, having minimal programming experience made it kind of difficult. However, I feel I have come up with a better way to print things to a file. Currently, I am printing to notepad, but I think it can easily be changed to word.

    I used 2 access test tables to look at the feasibility of doing it 'my way'.

    The structure is as follows:

    +Table1
    Table1ID
    Table1Field

    +Table2
    Table2ID
    Table2Field

    Using VBScript, I inserted the following code into a button.

    Sub CTRL129_21_OnClick(eventObj)

    Const iTempFolder = 2
    Dim oFS, oTempFolder, sFile, oTempFile, wshShell
    Dim sRun, sTemp

    Set oFS = CreateObject("Scripting.FileSystemObject")
    Set oTempFolder = oFS.GetSpecialFolder(iTempFolder)
    sFile = oFS.GetTempName

    sTemp = oFS.GetSpecialFolder(iTempFolder)
    If Right(sTemp,1) <> "\" Then
    sTemp = sTemp & "\" & sFile
    Else
    sTemp = sTemp & sFile
    End If

    Set oTempFile = oTempFolder.CreateTextFile(sFile)

    dim activeNode, numberNodesL1, numberNodesL2

    numberNodesL1 = XDocument.DOM.selectNodes("//d:Table1").length


    for i = 1 to numberNodesL1
    activeNode = "//d:Table1[" & i & "]/"
    oTempFile.WriteLine XDocument.DOM.selectSingleNode(activeNode & "@Table1Field").text
    numberNodesL2 = XDocument.DOM.selectNodes(activeNode & "/d:Table2").length

    for j = 1 to numberNodes2
    activeNode = "//d:Table1[" & i & "]/d:Table2[" & j & "]/"
    oTempFile.WriteLine " " + XDocument.DOM.selectSingleNode(activeNode & "@Table2Field").text
    next
    next


    Set wshShell = Createobject("WScript.Shell")
    sRun = "notepad.exe " & sTemp
    wshShell.Run sRun
    wshShell.AppActivate "NotePad"

    End Sub



    This code was written for two tables, but can easily be extended indefinatly by adding a numberNodesL variable and coding in a new for loop.

    In my humble opinion, much much easier than the Word wizard.



    Oh, and by the way, YOU'RE welcome - a little SNL humor there.
  • 05-02-2007 09:06 AM In reply to

    Re: Finally an easy way to print to text, or word

    Hi trufooser,

    Thanks a lot for this cool code sample! Printing InfoPath forms has always been a pain, and this should make it much easier! Thanks again.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-04-2007 07:34 AM In reply to

    Re: Finally an easy way to print to text, or word

    Matt,

     I am new to InfoPath. How do I keep the rows in repeating tables or repeating tables themselves breaking over across the pages. I saw your one of your suggestions on this subject, and it seemed a bit diffiult, as I have no programming experience. Is there an easier way?

  • 06-04-2007 10:10 AM In reply to

    Re: Finally an easy way to print to text, or word

    Hi SShariq and welcome to the forum!

    I hate to break it to you, but printing from InfoPath has always been very painful! There really is no easy way to do it.  What you could try is shredding your XML forms into a relational database with our DBXL tool, and then creating a SQL Report on top of this.  However, this is still not terribly easy.

    Good luck!

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.