Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / July 2005

Tip: Looking for answers? Try searching our database.

Cmd Button to Create a new, blank form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
abc - 22 Jul 2005 13:43 GMT
I need to add a button on my form so that the user can 'Create a new,
blank form'.

I know its one of the options in the 'submit' function, but i really
need the additional button.

Help appreciated!
Scott L. Heim [MSFT] - 22 Jul 2005 14:26 GMT
Hi,

When you use the built-in "submit" function to open a new, blank form it is
using the forms "template.xml" file and the "replaceChild" method to
re-load empty nodes. As such, you will need to write custom script to
execute this functionality.

Here is some sample code (VBScript) that I used on the click event of a
button - at the end of the code I have also noted where you will need to
make changes.

'This code provides the same functionality as using the "New Record" button
    Dim domTemplate
    Set domTemplate = CreateObject("MSXML2.DomDocument.5.0")
   
    domTemplate.async = false
    domTemplate.load("template.xml")
   
    If domTemplate Is Nothing Then
        XDocument.UI.Alert "Could not load the template!"
    Else
        Dim strMsg
        Dim retVal
       
        strMsg = "The document has not been saved! Do you want to save these
changes?"
        retVal = Msgbox(strMsg, vbExclamation + vbYesNo, "Create a new, blank
form")
       
        If retVal = 6 Then 'Yes
            Msgbox "Save this form and then click the button to create a new form.",
vbOkOnly
            Exit Sub
        Else
            Dim existingDataFields
            Set existingDataFields = XDocument.DOM.selectSingleNode("//my:myFields")
            domTemplate.setProperty "SelectionNamespaces",
"xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-
22T13:02:12"""
            Dim newDataFields
            Set newDataFields = domTemplate.selectSingleNode("//my:myFields")
            existingDataFields.parentNode.replaceChild
newDataFields.cloneNode(true), existingDataFields
           
            Set existingDataFields = Nothing
            Set domTemplate = Nothing
            Set newDataFields = Nothing
        End If
    End If

* Locate the lines of code above that start with the following:

    Set existingDataFields = XDocument.DOM.selectSingleNode
    Set newDataFields = domTemplate.selectSingleNode

    You will notice that each of these uses: "//my:myFields" - depending on
how you built your InfoPath solution, you may have a different root node
name and a different namespace. This needs to match your solution.

** Locate the line of code above that starts with the following:

    domTemplate.setProperty "SelectionNamespaces",

    This sets up a "SelectionNamespaces" property so we can access the nodes
from the "domTemplate." So again, the namespace needs to match your
solution and the timestamp at the end needs to match as well. An easy way
to get this namespace correct is to simply double-click your XSN file and
save the blank form. Open that form with, say Notepad, and near the top you
will see an entry for your top-level namespace.

I hope this helps!
   
Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
abc - 22 Jul 2005 16:08 GMT
Thanks!

When I run it... why do I get this error:

The following error occurred:

Unterminated string constant
File:script.js
Line:39
'This code provides the same functionality as using the "New Record"
button
Scott L. Heim [MSFT] - 22 Jul 2005 16:16 GMT
Hi,

As I mentioned in my sample code, that code is "VBScript" - it appears you
either already had "JScript" in your solution or did not change the form to
use "VBScript" instead of "JScript."
   
Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
abc - 22 Jul 2005 18:53 GMT
Oh yeah I forgot.. sorry!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.