Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-04-13
4
232 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

790 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