Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect to specific Outlook Folder 1

Status
Not open for further replies.

air1access

Technical User
Jan 27, 2008
123
US
Below is code I'm working with.
It works just fine. BUT - I need to connect to a different inbox, and a folder in that inbox...
Right now it connects to the folder "HPMS" in MY inbox... But I need to connect to a different inbox - different folder in that inbox..
I can't figure it out...!!

any suggestions..?

Private Sub Form_Load()
'Import Email From The Inbox
Dim rst As Recordset
Dim db As Database
Dim strSearchString As String
Dim strSearchChar As String
Dim strChrPos As String
Dim strBaseMessage As String
'Set up Outlook Objects
Dim Outlook As New Outlook.Application
Dim OutlookNS As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim MyFolder As Outlook.MAPIFolder
Dim MailItem As Outlook.MailItem
Dim objItems As Outlook.Items
Dim iNumContacts As Integer
Dim i As Integer

Set db = CurrentDb()
Set rst = db.OpenRecordset("HPMS_eMails")
Set OutlookNS = Outlook.GetNamespace("MAPI")
Set cf = OutlookNS.GetDefaultFolder(olFolderInbox)
Set MyFolder = cf.Folders("HPMS")
Set objItems = MyFolder.Items

DoCmd.RunSQL "DELETE * FROM HPMS_eMails;"

iNumContacts = objItems.Count
If iNumContacts <> 0 Then
For i = 1 To iNumContacts
If TypeName(objItems(i)) = "MailItem" Then
Set MailItem = objItems(i)

If MailItem.Subject Like "Marketing Event Upload Submission Status*" Then
rst.AddNew
rst!Entry_ID = MailItem.EntryID
rst!Sender = MailItem.Sender
rst!Recieved = MailItem.ReceivedTime
rst!To = MailItem.To
rst!Subject = MailItem.Subject
rst!Body = MailItem.Body
rst!UnRead = MailItem.UnRead
rst.Update
End If
End If
Next i
rst.Close
'DisplayMessage "All Email Has Been Imported"
Else
DisplayMessage "There Is No Email To Be Imported"
End If

Me.lstEmails.Requery
 
A declaration is not an executable statement.

STEP through your code until you arrive at a statement containing that object.

Also, do you have Option Explicit as the first statement in your module?

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
The struggle is real..!!

I do have Option Explicit... I tried with & without it...

'Set up Outlook Objects
Dim OutlookApp As New Outlook.Application
Dim OutlookNS As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim MyFolder As Outlook.MAPIFolder
Dim MailItem As Outlook.MailItem
Dim objItems As Outlook.Items
Dim iNumContacts As Integer
Dim i As Integer

Set OutlookNS = OutlookApp.GetNamespace("MAPI")
Set cf = OutlookNS.GetDefaultFolder(olFolderInbox)
Set MyFolder = cf.Folders("MarketPOINT Sales Integrity").Folders("Inbox").Folders("HPMS Confirmations")
Set objItems = MyFolder.Items

I can't get past -- Set MyFolder = cf.Folders("MarketPOINT Sales Integrity").Folders("Inbox").Folders("HPMS Confirmations") -- It generates an error here.
Says: "Object cannot be found
 
I do have Option Explicit... I tried with & without it.

You should NEVER EVER try to execute code without Option Explicit. This has NOTHING to do with any specific line of code. It is your safety net, that your code contains no "illegal" stuff.

With the assumption that you have Option Explicit...

...what do you see in cf after you execute the Set cf = ... statement?

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
SkipVought,
I'm having a hard time following ya...
I really don't know how to get this to work they way I want. I know its possible - I just don't understand how to connect to the different mailbox, and the folders in that mailbox....
I don't understand how to use the watch tool, or understand the error messages....
 
air1access,

It's easy for any of us to do: keep worrying about the end goal instead of the tiny steps to reach the goal. The latest items Skips trying to help you with are trying to get those small steps covered. When you're dealing with code, it's often the tiny minuscule items that can cause something "not to work". Just take a breathe - or by now I guess you have [smile], and try to work through the questions and answers. You could end up solving the whole problem once you get through one or two small quirks/issues.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
I don't understand how to use the watch tool."

Did you carefully read the FAQ I posted? It's detailed. Don't give up. There are some things code wise, that only YOU can do.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top