Results 1 to 1 of 1

Thread: [FAQ's: OD] How do I show a custom template?

Threaded View

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    [FAQ's: OD] How do I show a custom template?

    If you have created a custom Template Form then you can automate the loading of it and present it to the user to fil out and/or print.

    This can be done one of two ways:
    1. Local Automation of InfoPath by using the InfoPath Object Model.
    2. Publishing your Template on an Intranet or the Internet for viewing/filling in using a standard web browser.


    Here is one example of automating InfoPath using the IOM:




    VB 6 Code Example and InfoPath 2003:

    VB Code:
    1. Option Explicit
    2. 'Add a reference to MS InfoPath xx.0 Object Library
    3.  
    4. 'Declare an Application and Document object variable for use throughout the VB 6 Form
    5. Private moApp As InfoPath.Application
    6. Private moXDoc As InfoPath.XDocument
    7.  
    8. Private Sub Command1_Click()
    9.    
    10.     On Error GoTo MyError
    11.     'Open your custom template in presentation view.
    12.     Set moXDoc = moApp.XDocuments.NewFromSolution("C:\Development\Tips\InfoPath FAQ - Custom Template\RobDog888.xsn")
    13.     'Notify the user that its open
    14.     moXDoc.UI.Alert ("RobDog888.xsn Template Opened - Meow!")
    15.     Exit Sub
    16.    
    17. MyError:
    18.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, "RobDog888s Office Development InfoPath FAQ Example"
    19. End Sub
    20.  
    21. Private Sub Form_Load()
    22.    
    23.     On Error GoTo MyError
    24.     'Create an instance of the Application object
    25.     Set moApp = New InfoPath.Application
    26.     Exit Sub
    27. MyError:
    28.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, "RobDog888s Office Development InfoPath FAQ Example"
    29.     Unload Me
    30. End Sub
    31.  
    32. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    33.     Dim i As Integer
    34.     'Upon program termination we check if any forms are still open
    35.     'If so then we will close then to release all references
    36.     If moApp.XDocuments.Count > 0 Then
    37.         For i = moApp.XDocuments.Count - 1 To 0 Step -1
    38.             moApp.XDocuments.Close (i)
    39.         Next
    40.     End If
    41.     'Terminate the InfoPath application
    42.     moApp.Quit True
    43.     Set moApp = Nothing
    44. End Sub



    VB.NET 2003 Code Example: Coming Soon!
    Last edited by RobDog888; Jul 10th, 2006 at 04:30 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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