Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-13
4
Medium Priority
?
242 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

704 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