Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

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

22 Experts available now in Live!

Get 1:1 Help Now