Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/171158

From BetaArchive Wiki

Article ID: 171158

Article Last Modified on 2/12/2007



APPLIES TO

  • Microsoft Outlook 97 Standard Edition



This article was previously published under Q171158

SUMMARY

This article demonstrates how to use Visual Basic for Applications to access data from a Grid control in a Microsoft Outlook 97 item.

NOTE: The Grid control is not included with Microsoft Office 97 or Outlook To obtain the Grid control, run Microsoft Visual Basic, version 4.0 or 5.0 setup.

MORE INFORMATION

Create the Form with Grid control

  1. In Outlook, create a new e-mail message.
  2. On the Tools menu of the message, click Design Outlook Form.
  3. Click the (P.2) tab.
  4. On the Form menu, click Control Toolbox to display the Toolbox dialog.
  5. Drag a Grid control to (P.2) of the form. The default name of the Grid control is Grid1.


NOTE: If the Toolbox does not contain a Grid control, you must first add the Grid control to the Toolbox. To do this, right-click a blank area of the toolbox, and click Custom Controls on the shortcut menu. In the Available Controls list, click to select the Grid Control check box, and then click OK.

  1. On the Tools menu of the message, click Design Outlook Form to exit design mode. Leave the Untitled form that contains the Grid control open.

Create the Visual Basic for Applications Code

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 Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

The following code sample demonstrates how to reference a Grid control from any Office program that supports Visual Basic for Applications (VBA). This example generates a random number between one and six, and then assigns that number to the Grid control in an Outlook item. The code then retrieves and displays the value from the Grid control in a message box.

With the Untitled form open, run the following code from any Office 97 Application:

   Public Sub OlGridExample()

   '*********************************************************************
   ' In this example the Grid control is on tab P.2 of the form.
   ' The form is open, and is not in design mode.
   '*********************************************************************

   Set objOutlook = Nothing
   Set objOutlook = CreateObject("Outlook.Application")
   Set objNameSpace = objOutlook.GetNamespace("MAPI")
   Set objInspector = objOutlook.ActiveInspector
   Set objItem = objInspector.CurrentItem

   '*********************************************************************
   ' Reference the Grid control on the modified Form.
   '*********************************************************************
   Set Controls = objItem.GetInspector.ModifiedFormPages("P.2").Controls
   Set ctrlGrid = Controls("Grid1")

   '*********************************************************************
   ' Populate the Grid control with data.
   '*********************************************************************
      ctrlGrid.Col = 1
      ctrlGrid.Row = 0
      ctrlGrid.Text = "Test"

      ctrlGrid.Col = 1
      ctrlGrid.Row = 1
      ctrlGrid.Text = Int((6 * Rnd) + 1)  ' Generate random value
                                          ' between 1 and 6.

   '*********************************************************************
   ' Retrieve and display the Grid control data in a message box.
   '*********************************************************************
      ctrlGrid.Col = 1
      ctrlGrid.Row = 0
      dataString1 = ctrlGrid.Text

      ctrlGrid.Col = 1
      ctrlGrid.Row = 1
      dataString2 = ctrlGrid.Text

      MsgBox "The value set for " & dataString1 & " is " & dataString2

   End Sub
                

REFERENCES

For more information about creating solutions with Microsoft Outlook 97, please see the following articles in the Microsoft Knowledge Base:

166368 OL97: How to Get Help Programming with Outlook

170783 OL97: Q&A: Questions about Customizing or Programming Outlook



Additional query words: OutSol OutSol97

Keywords: kbcode kbhowto kbprogramming KB171158