Solved

Help with ADO (not .NET) code for adding contact to MAPI folder

Posted on 2004-04-13
4
442 Views
Last Modified: 2013-12-25
I can't get the following subroutine to work. It's meant to add a contact to a MAPI public folder. Can anyone tell me where I'm going wrong? It returns the error message: "Run-time error ‘-2147217895 (80040e19)’: Object or data matching the name, range, or selection criteria was not found within the scope of this operation." when it tries to open the record.

Also, can you please explain why the first version of strUrlFolder (commented out) doesn't work?

Thanks

---------------------------------------------------

Sub ADO_AddContactToMAPIFolder()
    Dim strUrlFolder As String
   
    'strUrlFolder = "http://server1/exchange/grandmas.org.uk/public folders/all public folders/dublin contacts/Peter Neely.eml"
    strUrlFolder = "file://./backofficestorage/grandmas.org.uk/public folders/all public folders/dublin contacts/Peter Neely.eml"

    With New ADODB.Record
        .Open strUrlFolder, , , adCreateOverwrite
        .Fields("DAV:contentclass") = "urn:content-classes:person"
        .Fields("urn:schemas:contacts:givenName") = "Peter"
        .Fields("urn:schemas:contacts:sn") = "Neely"
        .Fields("http://schemas.microsoft.com/exchange/outlookmessageclass") = "ipm.contact"
        .Fields.Update
    End With
End Sub
0
Comment
Question by:PNeely
  • 2
4 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10835484
this is NOT how you make use of an ADO recordset:

    With New ADODB.Record
        .Open strUrlFolder, , , adCreateOverwrite
        .Fields("DAV:contentclass") = "urn:content-classes:person"
        .Fields("urn:schemas:contacts:givenName") = "Peter"
        .Fields("urn:schemas:contacts:sn") = "Neely"
        .Fields("http://schemas.microsoft.com/exchange/outlookmessageclass") = "ipm.contact"
        .Fields.Update
    End With


for one thing, a Recordset MUST be associated with a Connection , which in turn has an associated ConnectionString.

You appear to not understand what ADO recordsets are about.

You cannot use ADO to send email messages, which is what you appear to be attempting here.

AW
0
 

Author Comment

by:PNeely
ID: 10842673
Thanks Arthur. You're right -- I'm new to all things ADO and probably don't understand recordsets properly -- which is why I'm posting here.

I copied the above lines of code from a book I've been reading about ADO and Exchange, but I seem to have got something wrong.

Can anyone help put their finger on it?

Thanks
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10846969
First, you need an ADODB.Connection Object, and I have no clue as to how to create that to connect to Outlook.  I was not weven aware that ADO could be used in connection (pardon the pub, ooh, AM I bad!!!), with Outlook.

If you have a book, then you must be missing some details, becuase this code looks VERY suspect.

AW
0
 

Accepted Solution

by:
DaveKane earned 250 total points
ID: 10894842
Actually, using the Exchange OLEDB provider you do not need to instantiate a connection object to open an ADODB.Record (as apposed to a recordset). You can open a Record simply by specifying a valid URL, assuming that your account has the required permissions in that folder to perform that operation. So that code should work for Exchange 2000/2003, but your account may lack permissions.

As for the commented out URL, an HTTP-style URL for a public folder should point to the "public" virtual directory. If "dublin contacts" is just below All Public Folders in the public folder hierarchy it would look like this:

strUrlFolder = "http://<server_alias>/public/dublin contacts/Peter Neely.eml"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

948 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

22 Experts available now in Live!

Get 1:1 Help Now