Solved

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

Posted on 2004-04-13
4
240 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
[X]
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
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses
Course of the Month6 days, 15 hours left to enroll

623 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