Microsoft Office 2000/Visual Basic Programmer's Guide   

Understanding Discussions

The Discussions collection contains all the Discussion objects associated with each level of discussion on a page. In turn, each Discussion object may have a Discussions collection that contains the Discussion objects related to that level of discussion.

A Discussion object represents an entry in a discussion. Each Discussion object has properties and methods you can use to specify the information that appears in the discussion and how and when changes are made to a discussion. Several of these properties map directly to settings you can specify in the Discussion fields to display section of the Discussion Options dialog box shown in Figure 12.11 earlier in this chapter.

You add a Discussion object to a Discussions collection by using the Discussions collection's Add method. You remove a Discussion object from a Discussions collection by using the Discussion object's Delete method.

The following code illustrates one technique you can use to get some basic information about the number of top-level discussions on a page:

Sub DisplayDiscussionInfo(strURL As String)
   Dim colDiscussions As Discussions
   Dim dscCurrent As Discussion
   Dim strMessage As String
   
   Set colDiscussions = OSE.OpenDiscussions(strURL)
   If colDiscussions.Count = 0 Then
      strMessage = "The page '" & strURL _
         & "' has no discussions."
   Else
      strMessage = "The page '" & strURL _
         & "' has " & colDiscussions.Count _
         & " discussions." & vbCrLf & vbCrLf
      For Each dscCurrent In colDiscussions
         With dscCurrent
            strMessage = strMessage _
               & "The top-level discussion number " _
               & .Index & " " _
               & IIf(.Discussions.Count > 0, "has one or more", _
               "does not have") & " replies." & vbCrLf
         End With
      Next dscCurrent
   End If
   MsgBox strMessage
End Sub

Each Discussion object in the Discussions collection represents a message in a discussion thread. If a page has a single message, the Discussions collection will contain a single Discussion object representing that message. If there are replies to a message, the Discussion object's Discussions property will return the collection of all replies to that message. This pattern is repeated for every Discussion object in a thread that has replies. Figure 12.12 illustrates the relationship between a Discussions collection and the Discussion objects it contains.

Figure 12.12 Relationship Between Discussions Collections and Discussion Objects

The Discussions collection for this page contains one Discussion object. That Discussion object's Discussions property would return a Discussions collection containing two Discussion objects, and so on. The following code sample illustrates how you would refer to the message titled "This is another reply to a reply." In this example, the colDiscussions variable represents the Discussions collection returned by the OpenDiscussions method:

With colDiscussions(1).Discussions(1).Discussions(2)
   MsgBox .Subject & " added to page at: " & .Timestamp
End With