How to Determine the Size of an Exchange 2000 Server Mailbox with ADO (255992)



The information in this article applies to:

  • Microsoft Exchange 2000 Server
  • ActiveX Data Objects (ADO) 2.5

This article was previously published under Q255992

SUMMARY

You can use ActiveX Data Objects (ADO) to determine the size of a user's mailbox. This artlcle contains sample code that demonstrates how to do this.

MORE INFORMATION

The following function determines the size of a mailbox by using ADO:

Private Sub Form_Load()
    Dim strMailBoxName As String
    strMailBoxName = "MyAlias"
    Debug.Print "Mailbox Size: " & dblGetMailboxSize(strMailBoxName)
End Sub

Private Function dblGetMailboxSize(strMailBoxName As String) As Double
    'Requires reference to:
    'Active DS Type Library (activeds.tlb)
    'Microsoft ActiveX Data Objects 2.5 Library  (msado15.dll)
    
    Dim Info As New ADSystemInfo
    Dim sDomainName As String
    Dim sUserName As String
    Dim mailboxSZ As Double
    Dim sURL As String
 
    Dim sSQL As String
    Dim Rs As New ADODB.Recordset
    Dim Rec As New ADODB.Record
    
    mailboxSZ = 0
    sDomainName = Info.DomainDNSName
    sUserName = strMailBoxName
    
    sURL = "file://./backofficestorage/" & sDomainName & _
            "/MBX/" & sUserName
    Rec.Open sURL
    
    sSQL = "Select"
    sSQL = sSQL & " ""http://schemas.microsoft.com" & _
                  "/exchange/foldersize"" "
    sSQL = sSQL & ", ""DAV:displayname"" "
    sSQL = sSQL & " from scope ('shallow traversal of " & Chr(34)
    sSQL = sSQL & sURL & Chr(34) & "')"
    sSQL = sSQL & "Where ""DAV:isfolder""=true"
    
    Rs.Open sSQL, Rec.ActiveConnection
    
    If Not Rs.EOF Then
        Rs.MoveFirst
    End If
    
    While Not Rs.EOF
        'Uncomment the following lines if you would like to<BR/>
        'see the size of each folder
        'Debug.Print Rs.Fields("DAV:displayname").Value
        'Debug.Print Rs.Fields("http://schemas.microsoft.com" & _
        '                     "/exchange/foldersize").Value
        mailboxSZ = mailboxSZ + _
                    Rs.Fields("http://schemas.microsoft.com" & _
                    "/exchange/foldersize").Value
        Rs.MoveNext
    Wend
    dblGetMailboxSize = mailboxSZ
    Rs.Close
    Rec.Close
End Function
				

Modification Type:MinorLast Reviewed:4/25/2005
Keywords:kbhowto kbprogramming KB255992