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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit Outlook Inbox Data from Access 1

Status
Not open for further replies.

air1access

Technical User
Jan 27, 2008
123
US
I have a command button on a form - that runs a piece of code...
It connects to a Outlook Inbox, and updates the "Categories" field in the email data.

I almost have it working...! Ha..!
It updates the data/emails in outlook but not the EntryID I'm searching for. It just updates all of the emails in the inbox..
Its not "finding" the EntryId that is in the recordset - rstAccessTable...
Here is what I'm working with... Any suggestions...?


Set rstAccessTable = db.OpenRecordset("SELECT KY_InBox_Wrking_tbl.EntryID, KY_InBox_Wrking_tbl.Categories " & _
"From KY_InBox_Wrking_tbl WHERE (((KY_InBox_Wrking_tbl.EntryID)=getglobal('GBLEntryID')));", dbOpenDynaset)

Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")

Set objFolder = objnSpace.Folders("Escalation.KY.EnBHIXSupport").Folders("Inbox")


Set objItems = objFolder.Items
iNumMessages = objItems.Count
If iNumMessages <> 0 Then
For i = 1 To iNumMessages
If TypeName(objItems(i)) = "MailItem" Then
Set cMail = objItems(i)

rstAccessTable.FindFirst "[EntryID] = '" & cMail.EntryID & "'"
cMail.Categories = rstAccessTable!Categories
cMail.Save
End If
Next i
End If
 
Does anybody have any suggestions on how I can get this to work?
Thanks in advance..!!
 
You are updating your mail items whether or not an item is found in the recordset...

Code:
Set objFolder = objnSpace.Folders("Escalation.KY.EnBHIXSupport").Folders("Inbox")


Set objItems = objFolder.Items
iNumMessages = objItems.Count
If iNumMessages <> 0 Then
     For i = 1 To iNumMessages
          If TypeName(objItems(i)) = "MailItem" Then
               Set cMail = objItems(i)

               rstAccessTable.FindFirst "[EntryID] = '" & cMail.EntryID & "'"
               [red]IF Not rstAccessTable.NOmatch Then [/red]
                    cMail.Categories = rstAccessTable!Categories
                    cMail.Save
               [red]End If [/red]
          End If
     Next i
End If
 
Thank you lameid..!!
I your example works fine..!! Thank you..!!!

Do you know of a way to change the font color of the email inbox in outlook...?
Based on the 'Categories' column...
 
Offhand, no.

You might try forum707 which is a generic VBA forum. More expertise on the various object models there. Another approach, think about how you would do the steps manually in Outlook and then search how to do those things in VBA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top