Platform SDK: Exchange 2000 Server

Enumerating All Recordset Fields

[This is preliminary documentation and subject to change.]

This example demonstrates how you can obtain all field names and values for each record in a recordset.

[VBScript]
Dim Rec
Dim Rs
Dim strSource
Dim strQ
Dim fld
Dim flds
Dim iX

Dim DomainName
Dim strLocalPath

'specify your own domain
DomainName = "microsoft.com"
'specify a URL to folder or item
strLocalPath = "mbx/user1/inbox"

Set Rec = CreateObject("ADODB.Record")
Set Rs = CreateObject("ADODB.Recordset")

'source URL
strSource = "file://./backofficestorage/" & DomainName & "/" & strLocalPath

Rec.Open strSource

'Construct the SQL query to run on the folder --
'To avoid confusion in escaping quotes,
'Chr(34)'s are used to delimit the URL

strQ = "select *"
strQ = strQ & " from scope ('shallow traversal of "
strQ = strQ & Chr(34) & strSource & Chr(34) & "')"

Rs.Open strQ, Rec.ActiveConnection

Rs.MoveFirst

iX = 1
Response.Write "<FONT FACE=ARIAL SIZE=2>"
While Not Rs.EOF
   Response.Write "<b>RECORD: " & iX & "</b> -------------------------------<br>"
   Set flds = Rs.Fields
   For Each fld in Flds
      Response.Write fld.Name & "<br>"
      Response.Write "&nbsp;&nbsp;" & fld.Value & "<br>"
      Response.Write "</p>"
   Next
   iX = iX + 1
   Rs.MoveNext

Wend


Rs.Close
Rec.Close

The following routines print field names and values for an ADO Record object and a CDO Message object.

[Visual Basic]
Sub EnumerateCollectionRecord(strURL As String)
Dim Rec As New ADODB.Record
Dim x As Integer

'assume strURL contains a valid URL
Rec.Open strURL

For x = 0 To Rec.Fields.Count - 1
        Debug.Print Rec.Fields(x).Name
        Debug.Print Rec.Fields(x).Value
        Debug.Print "---"
Next
End Sub

Sub EnumerateCollectionMessage(strURL As String)
Dim iMsg As New CDO.Message
Dim x As Integer

'open with the passed URL variable
iMsg.DataSource.Open strURL

For x = 0 To iMsg.Fields.Count - 1
        Debug.Print iMsg.Fields(x).Name
        Debug.Print iMsg.Fields(x).Value
        Debug.Print "---"
Next

End Sub