ID: Q171158
The information in this article applies to:
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 97. To obtain the Grid control, run Microsoft Visual Basic, version 4.0 or 5.0 setup.
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.
6. 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.
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 the Microsoft fee-based consulting line at (800) 936-5200. 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/refguide/default.asp
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
For more information about creating solutions with Microsoft Outlook 97, please see the following articles in the Microsoft Knowledge Base:
Article-ID: Q166368
Title : OL97: How to Get Help Programming with Outlook
Article-ID: Q170783
Title : OL97: Q&A: Questions about Customizing or
Programming Outlook
Additional query words: OutSol OutSol97
Keywords : kbcode kbprg
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 17, 1999