Cmd Button to Create a new, blank form

A

abc

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!
 
S

Scott L. Heim [MSFT]

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.
 
A

abc

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
 
S

Scott L. Heim [MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top