我可以在Access股票程序中添加一个按钮来搜索Outlook吗?

时间:2011-08-19 12:29:01

标签: ms-access outlook outlook-2007 ms-access-2010

有没有办法在访问数据库上创建一个自动搜索Outlook的按钮?我的想法是在电子邮件地址旁边有一个按钮,可以点击它,它会打开Outlook,或者如果它打开就跳转到Outlook,并搜索客户电子邮件地址的所有项目?

1 个答案:

答案 0 :(得分:2)

下面是一个VBA子程序,它接受搜索字符串并在现有的Outlook实例中搜索或创建要搜索的新实例。在Office 2010中测试。如果其他人将使用它,那么值得加入一个真正的错误处理程序。

您需要引用“Microsoft Outlook 14.0对象库”或您拥有的任何版本。您可以通过Tools-> References。在

如果您感觉有兴趣,可以借助AdvancedSearch方法在Access中显示搜索结果。

Sub outlookSearch(searchString As String)
Dim app As Outlook.Application

'This will throw an error if there's no instances of Outlook running
'   so resume after the error.
On Error Resume Next
Set app = GetObject(, "Outlook.Application")
On Error GoTo 0 'Replace this with a real error handler

'If the app variable is empty
If app Is Nothing Then
    'Create a new instanc eof outlook
    Set app = CreateObject("Outlook.Application")
    'Add an explorer showing the inbox
    app.Explorers.Add app.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    'Make the explorer visible
    app.Explorers(1).Activate
End If

'Search all folders for searchString
app.ActiveExplorer.search searchString, olSearchScopeAllFolders

Set app = Nothing
End Sub
相关问题