How to use field value to create the path for export method? - InfoPath Dev
in

InfoPath Dev

How to use field value to create the path for export method?

Last post 10-21-2013 01:46 PM by NewbieBlues. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 10-20-2013 07:43 PM

    How to use field value to create the path for export method?

    Hello all,

    I tried to modify

    	Me.CurrentView.Export("C:\MyView.pdf", ExportFormat.Pdf)
    

    by replacing "C:\MyView.pdf" with a field value.  My form's filename will change each time it's generated and I am trying to create a button that will switch the view, then export that view to a .pdf file saved to a network location.  I create the  filename and path by concatenating a field with other text in a read-only textbox control.

    I call my button "b_CREATE" and my switched view "v_CREATE".  I've enabled full trust but cannot get it to work without errors.  I've never programmed VB / InfoPath before, only VBA with Outlook and Word, and I'm fairly certain I'm missing something simple. 

    I'll be very grateful for any guidance or help you might offer.  Here is the code I have:

    Public Sub b_CREATE_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    Me.ViewInfos.SwitchView("v_CREATE")

    Dim myNAV As XPathNavigator = MainDataSource.CreateNavigator()

    Dim myFIELDVALUE As String = myNAV.SelectSingleNode("//myFIELD", NamespaceManager).Value

    Me.CurrentView.Export(myFIELDVALUE, ExportFormat.Pdf)

    End Sub

  • 10-21-2013 08:46 AM In reply to

    Re: How to use field value to create the path for export method?

     Hi - does your code work with a hardcoded value in the export statement? I'm going to guess that your XPath here is wrong:

    Dim myFIELDVALUE As String = myNAV.SelectSingleNode("//myFIELD", NamespaceManager).Value

    In the main data source of your form, in the designer, right click the field you want and select Copy XPath. Then paste that in the quotes where you have //myFIELD right now.

    Hilary Stoupa

  • 10-21-2013 10:26 AM In reply to

    Re: How to use field value to create the path for export method?

    Thank you!  Yes, you are correct:  I had the wrong XPath.  (sigh, ignorance is not bliss...)

    I've corrected it and now receive an error message that "InfoPath cannot execute any view-related object model calls.  The view is not ready."

    I had the same results when I instead tried to hardcode the value in the export statement.

    When I try to isolate the issue, it seems it's occurring at:

    Me.CurrentView.Export(myFIELDVALUE, ExportFormat.Pdf)

    Thanks for your help so far - if you have any further suggestions, please let me know.

    Thank you, again!

  • 10-21-2013 10:39 AM In reply to

    Re: How to use field value to create the path for export method?

     Where are you executing your code from? A button? A field change event? When the view is switching? Try searching online for the exact error message.

     

    Hilary Stoupa

  • 10-21-2013 11:29 AM In reply to

    Re: How to use field value to create the path for export method?

    Thank you - I 'm executing the code from a button.  I will search online for the error message.  Thanks!

  • 10-21-2013 11:45 AM In reply to

    Re: How to use field value to create the path for export method?

     Is your button doing anything else? or just executing the code for the export?

    Hilary Stoupa

  • 10-21-2013 12:23 PM In reply to

    Re: How to use field value to create the path for export method?

    It switches the view and executes the export.  From searching more, it seems the switch is the issue and that a lot of VB coding is necessary to overcome it (all of it beyond me).  That made me realize perhaps I'm overthinking it.  If I instead used a single view with a page break, and set the page design properties to print page 2 of 2, I hoped the export would adhere to that - I tried it just now,  but it doesn't.  However, I was able to successfully export the view as a .pdf with a filename that matched the form field.  Unfortunately, along with it printing the unnecessary first page (where the user selects the data to populate the second page), the quality of the export is terrible.  It looks like a low-grade screenshot intead of a generated pdf.  I realize I expected it would work like MS Word when saving to PDF in terms of quality. 

     I'll research more about the page number printing and pdf quality.

     Thanks,

    Andy

  • 10-21-2013 12:37 PM In reply to

    Re: How to use field value to create the path for export method?

     Use two sections and conditional formatting to show / hide the one you want. We do that a lot for emailing. Here's a link that may help: http://www.infopathdev.com/forums/p/22656/78476.aspx

    Hilary Stoupa

  • 10-21-2013 01:46 PM In reply to

    Re: How to use field value to create the path for export method?

    Excellent - got that to work for the sections, thank you!

    Now, if I can get the .pdf quality increased this will be ready to go.  I'll keep searching on that one.

Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.