Solved

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

Posted on 2004-04-13
4
222 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:PNeely
  • 2
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 250 total points
ID: 10835443
This:

    With rst
        .ActiveConnection = cnn
        .Open
    End With

does NOT use the SQL string that you have defined:

try it this way:

    With rst
        .ActiveConnection = cnn
        .Open strSQL
    End With

AW
0
 

Author Comment

by:PNeely
ID: 10842740
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
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10846953
what error message are you getting?

AW
0
 

Author Comment

by:PNeely
ID: 10967228
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now