OL2000: How to Programmatically Create a Form

ID: Q238755


The information in this article applies to:
  • Microsoft Outlook 2000


SUMMARY

If you are creating an advanced solution using Outlook, you may have a requirement to programmatically create a form where the layout varies based on certain criteria. This article provides an overview and starting point for building this type of solution.


MORE INFORMATION

Unlike previous versions, Outlook 2000 was specifically designed so you can programmatically create forms.

IMPORTANT: You should carefully evaluate how you use this capability. The following key issues should be taken into account:

  • Depending on where forms and items are stored, solutions that repeatedly republish forms can place additional performance and resource burdens on a Microsoft Exchange Server.


  • These types of solutions can cause potential problems with the Outlook forms cache and you should carefully evaluate how this approach may impact the cache. In particular, ensure that forms that are published to multiple locations do not have the same name.


  • For additional information about the Outlook forms cache, click the article number below to view the article in the Microsoft Knowledge Base:
    Q207896 OL2000: How the Forms Cache Works
  • If you've already created items that use a published form, and then programmatically changed the form, there's a good chance that those items are one-offs. You should carefully plan and evaluate the use of one-off forms and how they relate to your forms solution.


  • For additional information about one-off forms, click the article number below to view the article in the Microsoft Knowledge Base:
    Q232303 OL2000: Working with Form Definitions and One-Off Forms
  • The Outlook object model does not directly support switching between the compose and read pages of a form. Therefore, any programmatic changes you make to a form are done on the compose pages, not the read pages. Trying to develop a workaround can be problematic and most likely will involve using the .Execute method on the CommandBars objects to toggle a form between compose and read pages.


Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

Sample Code to Add a Control to a Form

The following Microsoft Outlook Visual Basic for Applications code illustrates how you can programmatically add a Label and Listbox control to a new page of the default Contact form. Be sure to reference the Microsoft Forms 2.0 Object Library before running the code.

Sub CreateForm()

   Dim oNewItem As Outlook.ContactItem
   Dim oInsp As Outlook.Inspector
   Dim oPage As Object
   Dim oLabel As MSForms.Control
   Dim oLB As MSForms.Control

   Set oNewItem = Application.CreateItem(olContactItem)
   Set oInsp = oNewItem.GetInspector

   ' Create a new form page called "My Page"
   Set oPage = oInsp.ModifiedFormPages.Add("My Page")

   ' Add the label to the form page
   Set oLabel = oPage.Controls.Add("Forms.Label.1", "lblCompanies", True)

   ' Size and position the label
   PlaceControl oLabel, 5, 10, 13, 100

   ' Set the caption of the label
   oLabel.Caption = "Companies:"

   ' Add the listbox to the form page
   Set oLB = oPage.Controls.Add("Forms.ListBox.1", "cmdCompanies", True)

   ' Size and position the listbox
   PlaceControl oLB, 18, 10, 50, 100

   ' Populate the listbox
   oLB.AddItem "Microsoft"
   oLB.AddItem "ACME"
   oLB.AddItem "Northwind"

   ' Change the form page so it defaults to "My Page"
   oInsp.SetCurrentFormPage "My Page"

   oNewItem.Display

   ' Clean up
   Set oListBox = Nothing
   Set oLabel = Nothing
   Set oPage = Nothing
   Set oInsp = Nothing
   Set oNewItem = Nothing

End Sub


Sub PlaceControl(Ctrl As MSForms.Control, T As Integer, _
                 L As Integer, H As Integer, W As Integer)
   Ctrl.Top = T
   Ctrl.Left = L
   Ctrl.Height = H
   Ctrl.Width = W
End Sub 
This code sample simply displays a newly created form. For additional information about how to programmatically create and publish a new custom form, click the article number below to view the article in the Microsoft Knowledge Base:
Q208520 OL2000: Programming Examples for Referencing Items and Folders
Refer to the Items.Add and CreateItemFromTemplate methods in the article.


REFERENCES

For additional information about available resources and answers to commonly asked questions about Outlook solutions, click the article number below to view the article in the Microsoft Knowledge Base:

Q146636 OL2000: Questions About Custom Forms and Outlook Solutions

Additional query words: OutSol OutSol2000 vbscript

Keywords :
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: January 3, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.