ShowModalDialog Method

Microsoft Office InfoPath

Displays a custom modal dialog box in a Microsoft Office InfoPath 2003 form.

expression.ShowModalDialog(ByVal bstrName As String, [ByVal varArguments As Variant], [ByVal varHeight As Variant], [ByVal varWidth As Variant], [ByVal varTop As Variant], [ByVal varLeft As Variant]) As Variant

expression    Required. An expression that returns a reference to the UI object.

bstrName Required String. The name of the .html file used for the modal dialog box.

varArguments Optional Variant. Specifies the arguments to use when displaying the modal dialog box. Can be any type of value, including an array of values.

varHeight Optional Variant. Sets the height of the modal dialog box.

varWidth Optional Variant. Sets the width of the modal dialog box.

varTop Optional Variant. Sets the top position of the modal dialog box relative to the upper left corner of the desktop.

varLeft Optional Variant. Sets the left position of the modal dialog box relative to the upper left corner of the desktop.

returns    Variant.

Security Level

3: Can be accessed only by fully trusted forms.

Remarks

The ShowModalDialog method of the UI object allows you to display custom dialog boxes to users as they fill out a fully trusted form. Custom dialog boxes are implemented as .html files created in any type of HTML editor, such as Microsoft FrontPage. You can use scripting code in a custom dialog box that interacts with the InfoPath object model if you pass objects to the custom dialog box using the varArguments parameter.

To use a custom dialog box in an InfoPath form, you must first add the .html file of the custom dialog box to the form's set of resource files by using the Resource Manager dialog box. The Resource Manager dialog box is available from the Tools menu in design mode. After you have added the custom dialog box file to the form, you can use the ShowModalDialog method to display it.

Note  Although the ShowModalDialog method can only be used in fully trusted forms, you can create a custom dialog box in standard forms using the showModalDialog method of the Dynamic HTML (DHTML) object model.

Example

In the following example, the ShowModalDialog method of the UI object is used to display a custom dialog box. Note that the XDocument object is passed to the custom dialog box using the varArguments parameter.

XDocument.UI.ShowModalDialog("SimpleDialog.htm", XDocument);

The following example is the HTML code used to implement a simple custom dialog box. Note the use of the dialogArguments property of the DHTML window object to get the values passed to the custom dialog box, which in this case is the XDocument object of the InfoPath object model, from the ShowModalDialog method. When a user clicks the Show Alert button in the custom dialog box, the source XML of the form's underlying XML document appears in a message box.

<html>
   <head>
      <script language="jscript">
         var gobjXDocument = null;

         function Initialize()
         {
            // Save a reference to the XDocument object.
            if (typeof window.dialogArguments == "object")
            gobjXDocument = window.dialogArguments;
         }
      </script>

      <title>A Simple Custom Dialog Box</title>
   </head>

   <body style="BACKGROUND-COLOR: window" onLoad="Initialize()">
      <strong>Click one of the following buttons:</strong>
      <br/>
      <br/>
      <div id="divButtons" tyle="align:center">
         <input id="btnShowAlert" style="WIDTH: 106px; HEIGHT: 24px" 
            onclick='gobjXDocument.UI.Alert(gobjXDocument.DOM.xml);' 
            type="button" size="21" value="Show Alert"></input>
         <input id="btnCancel" style="WIDTH: 106px; HEIGHT: 24px" 
            onclick="window.close();" type="button" size="21" 
            value="Cancel"></input>
      </div>
   </body>
</html>