Link to home
Start Free TrialLog in
Avatar of PNeely
PNeelyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Help with ADO (not .NET) code for querying MAPI folder

I can't get the following subroutine to work. It's meant to query a MAPI public folder and return the first record. Can anyone tell me where I'm going wrong? It returns the error message: "Run-time error ‘-2147217900 (80040e19)’:" when it tries to open the recordset at the end of the routine.

Also, can you please explain why the second version of 'strUrlFolder (commented out) doesn't work?

Thanks

(PS - the code includes a custom function called Quote that simply adds quotes around a string value.)

-------------------------------------------------------------------

Sub ADO_QueryMAPIFolder()
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strUrlFolder As String
    Dim strSQL As String
   
    strUrlFolder = "http://server1/exchange/grandmas.org.uk/public folders/all public folders/group contacts/"
    'strUrlFolder = "file://./backofficestorage/grandmas.org.uk/public folders/all public folders/group contacts/"
MsgBox strUrlFolder

    Set cnn = New Connection
    With cnn
        .Provider = "msdaipp.dso"
        .Open strUrlFolder
    End With
   
    If Err.Number = 0 Then
        MsgBox "Folder opened okay"
    Else
        MsgBox "Folder could not be opened"
        Err.Clear
    End If
   
    strSQL = "SELECT " & QUOTE("urn:schemas:contacts:givenName") & ", " & _
        QUOTE("urn:schemas:contacts:sn")
    strSQL = strSQL & " FROM SCOPE ('SHALLOW traversal of " & QUOTE(strUrlFolder) & "')"
MsgBox strSQL

    Set rst = New Recordset
    With rst
        .ActiveConnection = cnn
        .Open
    End With
MsgBox rst(1)
   
    rst.Close
    cnn.Close
   
    Set rst = Nothing
    Set cnn = Nothing
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PNeely

ASKER

Thanks. I did what you said but still get a run time error when the recordset attempts to open (rst.Open strSQL).

Maybe this is considered to be asking someone to do my homework for me. I'm new to this board, so I'm not sure what's protocol, but here's hoping anyway...

Peter
what error message are you getting?

AW
Avatar of PNeely

ASKER

Thanks Arthur for your comments. Sorry not to have replied sooner. Turns out this question isn't such a burning issue any more, so I'll close this question and award you the points.