PNeely
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://./backofficestorag e/grandmas .org.uk/pu blic 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:contact s:givenNam e") & ", " & _
QUOTE("urn:schemas:contact s: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
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://./backofficestorag
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:contact
QUOTE("urn:schemas:contact
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what error message are you getting?
AW
AW
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.
ASKER
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