Open InBox and go to date/message with VBA?

D

deko

I have an Access 2003 mdb that searches the Outlook Inbox for specific email
messages and displays the results in a datasheet. The datasheet contains
the Date_Received and Subject. What I'm trying to do is this: When the
user clicks on the field in the datasheet that contains the Date_Received, I
want to open Outlook, go to the Inbox and move to the first occurrence of
the Date_Received.

I've tried this, but no luck. How do I move to a message and/or date in the
Outlook Inbox?

Private Sub Date_Received_Click()
On Error GoTo HandleErr
Dim ol As Outlook.Application
Dim olns As NameSpace
Dim viw As View
Dim olCal As Outlook.MAPIFolder
Dim olExp As Outlook.Explorer
Dim dtmDate As Date
dtmDate = Me![Received]
Set ol = GetObject(, "Outlook.Application")
Set olns = ol.GetNamespace("MAPI")
If ol.ActiveExplorer Is Nothing Then
olns.GetDefaultFolder(olFolderInbox).Display
Else
Set ol.ActiveExplorer.CurrentFolder =
olns.GetDefaultFolder(olFolderInbox)
ol.ActiveExplorer.Display
End If
Set olExp = ol.ActiveExplorer.CurrentFolder.GetExplorer
Set viw = olExp.CurrentView
viw.GoToDate dtmDate
Exit_Here:
On Error Resume Next
Set ol = Nothing
Set olns = Nothing
Set olCal = Nothing
Set olExp = Nothing
Set viw = Nothing
Exit Sub
HandleErr:
Select Case Err.Number
Case 429 'if Outlook is not already open
Set ol = CreateObject("Outlook.application")
Resume Next
Case Else
modHandler.LogErr ("frmAllApptsDatasheet"), ("Date_DblClick")
End Select
Resume Exit_Here
End Sub
 
D

deko

For some reason my news server (news.sf.sbcglobal.net) does not seem
Then use Microsoft's newsserver:
news://msnews.microsoft.com/microsoft.public.outlook.program_vba

I didn't realize that was an option... works great!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top