<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Newbie Questions</title><link>https://www.infopathdev.com:443/forums/39.aspx</link><description>New to InfoPath? Search to see if your question has already been answered. If it has not, then ask it here or the appropriate topic forum.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: How to add a print button for InfoPath 2007 using VB</title><link>https://www.infopathdev.com:443/forums/thread/98930.aspx</link><pubDate>Thu, 04 Sep 2014 01:21:14 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:98930</guid><dc:creator>Hilary Stoupa</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/98930.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=39&amp;PostID=98930</wfw:commentRss><description>&lt;p&gt;Thanks for taking the time to write this up and share it with the community!&lt;/p&gt;</description></item><item><title>How to add a print button for InfoPath 2007 using VB</title><link>https://www.infopathdev.com:443/forums/thread/98884.aspx</link><pubDate>Mon, 01 Sep 2014 12:15:44 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:98884</guid><dc:creator>Robert King</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/98884.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=39&amp;PostID=98884</wfw:commentRss><description>&lt;p&gt;There are a few threads on here detailing how to add a button to a form in the 2007 version of InfoPath, which will allow you to print the form instead of doing so via file/print toolbar.&lt;/p&gt;
&lt;p&gt;None of the threads have&amp;nbsp;a proper detailed description of what to do.&amp;nbsp; Just bits and pieces that you have to then try and work out what to do with.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve written this thread to overcome this ... follow this and you will be able to do as I&amp;#39;ve done - insert a print button&amp;nbsp;on the form and when you click it, it will open up the&amp;nbsp;MS Office Print dialog box where you can select what to do.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve used the snipping tool within MS Office to insert some graphical images too.&lt;/p&gt;
&lt;p&gt;Here goes ...&lt;/p&gt;
&lt;p&gt;1. Click on Tools, then choose Form Options, and from there choose Programming&amp;nbsp;from the list under the &amp;quot;Category:&amp;quot; heading.&amp;nbsp;In the box entitled &amp;quot;Form Template Code Language&amp;quot;, choose Visual Basic.&amp;nbsp; In the box immediately underneath it entitled &amp;quot;Project location for Visual Basic and C# code:&amp;quot; set the directory path of where InfoPath is&amp;nbsp;going to save your VB code.&amp;nbsp; This can be anywhere you like.&amp;nbsp; It is worth noting at this point that there is one other important option on this same screen - Remove Code.&amp;nbsp; If you get to the end of this tutorial, you would have inserted and subsequently modified the &amp;quot;default&amp;quot; VB code generated&amp;nbsp;by default.&amp;nbsp; Therefore - IF YOU CLICK ON THE Remove Code BUTTON AFTER YOU FINISHED, YOU WILL WIPE TOTALLY ALL THE EXTRA CODE YOU&amp;#39;VE INSERTED, NO MATTER WHETHER THAT WAS&amp;nbsp;ONE LINE OR THOUSANDS OF LINES!&amp;nbsp; Therefore, my advice is to think very carefully before clicking on Remove Code!!&lt;/p&gt;
&lt;p&gt;Anyway, now you&amp;#39;ve set this&amp;nbsp;characteristic up,&amp;nbsp;this particular InfoPath form will generate and allow you to modify VB code.&amp;nbsp; In case you&amp;#39;re wondering, I&amp;#39;ve not tried using the C# function.&amp;nbsp; Therefore everything that now follows is associated with VB ONLY!&lt;/p&gt;
&lt;p&gt;2. In your form, you are going to need to insert a button, and edit&amp;nbsp;it.&amp;nbsp; Below is a screen shot showing a very simple layout in one of my forms.&amp;nbsp; It is on the last page, but obviously you can place&amp;nbsp;an equivalent looking button&amp;nbsp;any where you like.&amp;nbsp; You don&amp;#39;t need to edit it so it says what I&amp;#39;ve put either - you could disguise it as a button that does something else if you wish.&amp;nbsp; The text is not releveant - only the function underneath it.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.infopathdev.com/blogs/hilary/VBPrintPost/image001.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s what it looks like if you double click it.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.infopathdev.com/blogs/hilary/VBPrintPost/image003.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;To make this button simulate the Ctrl + P functionality otherwise available via the &amp;quot;File&amp;quot;&amp;nbsp;toolbar in InfoPath, click on the &amp;quot;Edit Form Code...&amp;quot; button.&lt;/p&gt;
&lt;p&gt;If you have not yet inserted any of&amp;nbsp;your own code into the form, a dialog window will briefly flicker telling you it is building the initial version of the VB scripted code.&amp;nbsp; This is done so that this InfoPath form has its default script built. (if you go back to point 1 and repeat the exercise, you should see that the Remove Code button is now active - it wasn&amp;#39;t before as no code existed up to this point).&lt;/p&gt;
&lt;p&gt;The number in the &amp;quot;ID:&amp;quot; box in the above diagram will vary according to how many functions, buttons etc. you have in your form.&amp;nbsp; The number you can see in my example is 284, as that&amp;#39;s how many controls there are in it.&amp;nbsp; It doesn&amp;#39;t matter what the number is, but it is relevant to the editing of the VB code.&lt;/p&gt;
&lt;p&gt;Anyway, as a consequence of pressing &amp;quot;Edit Form Code...&amp;quot;, you should now see another window which has been opened up in the &amp;quot;Microsoft Visual Studio Tools for Applications&amp;quot; tool.&amp;nbsp; This is what is used to maintain the VB code for this InfoPath form.&amp;nbsp;&amp;nbsp;The window display&amp;nbsp;shows many things, and I&amp;#39;m not about to explain Visual Studio Tools here.&amp;nbsp;&amp;nbsp;Suffice to say, that the product opens up in the section where you need to edit.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s a screen shot of what it looks like.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.infopathdev.com/blogs/hilary/VBPrintPost/image005.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;3. The cursor is already positioned where we want to edit. Replace the (green) line &amp;#39; Write your code here. with &amp;quot;Me.Print(2)&amp;quot; without the &amp;quot; quotes i.e. just Me.Print(2) &lt;/p&gt;
&lt;p&gt;This will ensure that when the button is pressed in the&amp;nbsp;InfoPath form, that the Ctrl + P functionality is replicated.&amp;nbsp; A window will appear&amp;nbsp;from which you can select what you want to do.&amp;nbsp; A screen image of that appears further down.&lt;/p&gt;
&lt;p&gt;If you do NOT want this print window to appear, and just want the form printed to your Windows pre-determined default printer, then remove the number 2 from within the brackets. i.e. Me.Print()&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now you have inserted one of the two options I&amp;#39;ve described,&amp;nbsp;here&amp;#39;s what the screen now looks like.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.infopathdev.com/blogs/hilary/VBPrintPost/image007.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;What we&amp;#39;ve effectively done is insert an instruction against the control called CTRL284_Clicked which is the same number as we saw against the ID: identifier on the Button Properties tab in InfoPath.&lt;/p&gt;
&lt;p&gt;In the case of my example, I&amp;#39;ve included the number 2 between the brackets, as I want the Print Window Options screen to appear when my users click on the button when they&amp;#39;re working on it in InfoPath.&lt;/p&gt;
&lt;p&gt;4. Close the&amp;nbsp; &amp;quot;Microsoft Visual Studio Tools for Applications&amp;quot; tool, by simply pressing the X in the top right.&amp;nbsp; This will save whatever the code looks like - you don&amp;#39;t have to independently save it before closing it.&lt;/p&gt;
&lt;p&gt;5. We are now back in the InfoPath form.&amp;nbsp; Therefore at this point, save and publish it to wherever you normally do.&amp;nbsp; In my case, I save it to a SharePoint web page. Then close InfoPath and go to your published location.&lt;/p&gt;
&lt;p&gt;6. Next, launch the published form, fill a few parts of it in, then click on that button.&lt;/p&gt;
&lt;p&gt;Below is what appears.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.infopathdev.com/blogs/hilary/VBPrintPost/image009.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the button has simulated Ctrl + P from the File menu.&lt;/p&gt;
&lt;p&gt;From here, select as you normally would.&lt;/p&gt;
&lt;p&gt;You may recall I said on my button &amp;quot;Click here to&amp;nbsp;print this form, or save it as a PDF&amp;quot;.&amp;nbsp; Printing is easy- just select which printer from the Print drop-down.&amp;nbsp; However if you want to save it as a PDF, I thoroughly recommend that at your site, the administration team install CutePDF writer (as the screen shot below shows).&amp;nbsp; This will not only then prompt you to say where you want the form saved in PDF format, but also what you want to call it.&amp;nbsp; The real big plus point here though, is that the integrity of the form is maintained.&amp;nbsp; It saves it to PDF and when you then open it in PDF it looks exactly the same as it does when viewed via InfoPath.&amp;nbsp; A far cry from the &amp;quot;export as PDF&amp;quot; functionality with InfoPath, which is really poor, and frequently misaligns your form whilst saving it as a PDF.&amp;nbsp; Have to say, that part of InfoPath is fairly rubbish!&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.infopathdev.com/blogs/hilary/VBPrintPost/image011.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;So - I know that might seem&amp;nbsp;like a lot of step and reading - but it 100% works.&lt;/p&gt;
&lt;p&gt;Good luck!&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>