Microsoft KB Archive/184786

From BetaArchive Wiki

Article ID: 184786

Article Last Modified on 3/1/2004



APPLIES TO

  • Microsoft Outlook 98 Standard Edition



This article was previously published under Q184786

SYMPTOMS

You use the SetColumns method in the Microsoft Outlook 98 object model and get unexpected results when working with a boolean (True/False) field.

CAUSE

When you use the SetColumns method with a boolean field, the value returned for True is incorrect and will cause unexpected results if used with a logical statement such as If...Then...Else.

WORKAROUND

Use either of these two work arounds:

  • Do not use the SetColumns method to increase performance when accessing boolean fields.
  • Use the SetColumns method with the boolean field, but alter your code so that it takes this into account. Using SetColumns, a field set to True will return a value of 1 instead of -1. Use this syntax to ensure that condition evaluates properly:

    If Item.Complete Then...

    The following syntax will return an incorrect result:

    If Item.Complete = True Then

    NOTE: You should not use the following syntax since it will cause your code to fail when this problem is fixed in a later version of Outlook:

    If CInt(Item.Complete) = 1 Then


STATUS

Microsoft has confirmed this to be a problem in Microsoft Outlook 98.

MORE INFORMATION

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:

The SetColumns method is used to increase performance when accessing standard Outlook fields through the Outlook object model.

For more information about using the SetColumns method, please see the following article in the Microsoft Knowledge Base:

184462 OL98: How to Use the SetColumns Method


Steps to Reproduce Problem

The following Microsoft Visual Basic (VB) or Microsoft Visual Basic for Applications automation code example illustrates the problem.

  1. Create a Tasks folder or use an existing Tasks folder if it is empty.
  2. Create two task items in the folder, setting the Subject fields to Test1 and Test2 or something comparable.
  3. Set the status of one of the items to Complete and save the item.
  4. Select the folder and then run the following automation code from VB or an Office application. Be sure to create a reference to the Outlook object library.

       Sub TestSetColumnsBoolean()
          Dim outapp As Outlook.Application
          Dim itms As Items
          Dim itm As Object
          Set outapp = New Outlook.Application
          Set itms = outapp.ActiveExplorer.CurrentFolder.Items
          itms.SetColumns "[Complete]"
          For Each itm In itms
             MsgBox itm.Subject & ":" & itm.Complete & ":" & CInt(itm.Complete)
             If itm.Complete = True Then
                MsgBox "Item is Complete"
             End If
          Next
       End Sub
                            

You will not get a dialog box indicating one of the items is complete because neither of the fields evaluate to -1.

REFERENCES

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

180826 OL98: Resources for Custom Forms and Programming

182349 OL98: Questions About Custom Forms and Outlook Solutions



Additional query words: OutSol OutSol98 VBScript Yes No On Off

Keywords: kbbug kbprogramming kbpending KB184786