A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Change default mailbox



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old March 4th 06, 04:44 PM posted to microsoft.public.outlook.program_vba
Hlewis
external usenet poster
 
Posts: 7
Default Change default mailbox

I am using the following code to pull emails out of outlook and put them in a
table in Access. The problem I'm having is that I want to pull emails from
an Inbox other than my default Inbox. How do I do that?

Option Compare Database
Option Explicit

Public Sub ImportOutlookItems()

'Define Variables
Dim Olapp As Outlook.Application
Dim Olmapi As Outlook.Namespace
Dim Olfolder As Outlook.MAPIFolder
Dim OlAccept As Outlook.MAPIFolder
Dim OlDecline As Outlook.MAPIFolder
Dim OlFailed As Outlook.MAPIFolder
Dim OlMail As Object 'Have to late bind as appointments e.t.c screw it up
Dim OlItems As Outlook.Items
Dim OlRecips As Outlook.Recipients
Dim OlRecip As Outlook.Recipient
Dim Rst As Recordset

'Open table TLMS_Cost
Set Rst = CurrentDb.OpenRecordset("TLMS_Cost")
'Create a connection to outlook
Set Olapp = CreateObject("Outlook.Application")
Set Olmapi = Olapp.GetNamespace("MAPI")
'Open the inbox
Set Olfolder = Olmapi.GetDefaultFolder(olFolderInbox)
Set OlItems = Olfolder.Items
'Set up the folders the mails are going to be deposited in
'Set OlAccept = Olfolder.Folders("Accept")
'Set OlDecline = Olfolder.Folders("Decline")
'Set OlFailed = Olfolder.Folders("Failed")
'Set up a loop to run till the inbox is empty (otherwise it skips some)
Do Until OlItems.Count = 0
'Reset the Olitems object otherwise new incoming mails and moving mails get
missed
Set OlItems = Olfolder.Items
For Each OlMail In OlItems
'For each email in the collection, check the subject line and process
accordingly
If OlMail.UnRead = True Then
OlMail.UnRead = False 'Keep mail mark as unread
Rst.AddNew
Rst!Date = OlMail.ReceivedTime
Rst!Time = OlMail.ReceivedTime
Rst!From = OlMail.SenderName
'Rst!Name = OlMail.SenderName
Rst!Email = OlMail.EmailAddress
Rst!Description = OlMail.Subject


If InStr(1, OlMail.Subject, " Hey you") 0 Then
Rst!Status = "Attending"
Rst!datesent = OlMail.ReceivedTime
'OlMail.Move OlAccept
ElseIf InStr(1, OlMail.Subject, "Decline") 0 Then
Rst!datesent = OlMail.ReceivedTime
Rst!Status = "Decline"
OlMail.Move OlDecline
Else
Rst!datesent = OlMail.ReceivedTime
Rst!Status = "Failed"
'OlMail.Move OlFailed
End If
Rst.Update
End If
Next
Loop
MsgBox "Your wish is my command. New mails have been checked. Please
check the TLMS_Cost for details", vbOKOnly
End Sub
--
Hlewis
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exchange Mailbox server prohibit from sending when reach mailbox size limit Milly Staples [MVP - Outlook] Outlook - General Queries 1 February 24th 06 07:41 PM
Can't change default delivery folder George Outlook - Installation 1 February 17th 06 07:59 PM
Running rules on mailbox other than the default Brian Beck Outlook - General Queries 1 February 3rd 06 10:26 PM
How do you change the default display form? Spike9458 Outlook - Using Contacts 1 January 30th 06 05:31 PM
How can I change the default calendar? AV Outlook - Calandaring 1 January 10th 06 04:29 PM


All times are GMT +1. The time now is 09:18 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.