以编程方式从access中导入Outlook项目
时 间:2009-08-20 08:28:11
作 者:Microsoft ID:4070 城市:杭州
摘 要:以编程方式从Access中导入Outlook项目
正 文:
您可以使用此代码为基础创建其他类型的约会、 备注、 任务,和如等的 Outlook 项目。
编程注意事项
下面的示例代码使用 Access 2002 中包含 Northwind 数据库。 如果 Office 安装到非默认位置,一定要更改到示例代码中数据库的路径。
您需要设置对 Microsoft Outlook 10.0 对象库的引用。 默认情况下,应设置对 Microsoft DAO 3.6 对象库,和 Microsoft Office 10.0 对象库的引用。
此示例中使用该字段类型是访问 Outlook 中同时的文字。 要将转换为其他类型的字段,您必须相应地修改代码。
联系人会自动放在处于相同级别为收件箱的默认联系人文件夹中。
此示例中使用该 CreateItem 方法创建新的 Outlook 联系人使用为默认联系人文件夹的默认窗体。 如果创建了自定义 Outlook 联系人窗体必须设置每个项目的邮件类域为您的自定义窗体的名称。
Microsoft 将提供仅,用于说明的编程示例,没有任何明示或暗示的保证,其中包括但不是限于,不对适销性和/或针对特定用途的适用性的暗示保证。 本文假定您熟悉演示的编程语言和工具用于创建和调试过程。 Microsoft 支持专业人员可以帮助解释某个特定过程的功能,但是他们不会修改这些示例以提供额外的功能或构建过程以满足您的特定需求。
如果您的编程经验有限,您可能需要与在 Microsoft 认证合作伙伴或 Microsoft 顾问服务。
示例代码
Sub ExportAccessContactsToOutlook()
' Set up DAO Objects.
Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = OpenDatabase _
("c:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb")
Set rst = oDataBase.OpenRecordset("Customers")
' Set up Outlook Objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim Prop As Outlook.UserProperty
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
With rst
.MoveFirst
' Loop through the Microsoft Access records.
Do While Not .EOF
' Create a new Contact item.
Set c = ol.CreateItem(olContactItem)
' Specify which Outlook form to use.
' Change "IPM.Contact" to "IPM.Contact.<formname>" if you've
' created a custom Contact form in Outlook.
c.MessageClass = "IPM.Contact"
' Create all built-in Outlook fields.
If ![CompanyName] <> "" Then c.CompanyName = ![CompanyName]
If ![ContactName] <> "" Then c.FullName = ![ContactName]
' Create the first user property (UserField1).
Set Prop = c.UserProperties.Add("UserField1", olText)
' Set its value.
If ![CustomerID] <> "" Then Prop = ![CustomerID]
' Create the second user property (UserField2).
Set Prop = c.UserProperties.Add("UserField2", olText)
' Set its value and so on....
If ![Region] <> "" Then Prop = ![Region]
' Save and close the contact.
c.Save
c.Close
.MoveNext
Loop
End With
End Sub
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- Inputbox输入密码打开查...(12.23)
- 【Access Dsum示例】...(12.16)
- Inputbox输入密码打开窗...(12.13)
- 【Access DCount示...(12.02)

学习心得
最新文章
- 用Access查询语句如何得到前3...(02.17)
- Access快速开发平台--导入导...(02.14)
- 按回车键后光标移动到下一条记录的V...(02.12)
- Access快速开发平台--要实现...(02.10)
- Access快速开发平台--让Pe...(02.08)
- 【Access Dsum示例】用D...(02.07)
- Access对子窗体的数据进行平均...(02.05)
- Access快速开发平台附件上传,...(01.18)
- 【IIF函数示例】用iif函数判断...(01.18)
- Access快速开发平台--如何获...(01.17)