S
Suggy1982
I have the following code in an Access VBA module, which loops through each
email in a specified email folder and then parse's out certain data items and
imports them into an access DB, which works fine.
The bit i am struggling with is after that. I want the code to then move the
email into a folder depending on one of the data items in the email.
I am not sure if i have DIM'd the target folder correctly, can anyone else?
Thanks
Adrian
CODE:
Sub Checkmail()
Dim o_Out_Items As items
Dim DestFolderPath As Outlook.MAPIFolder
Dim o_Item As Variant
Dim o_items As MailItem
Dim strmailbod As String
Dim toname As String
Dim myRecipient As Outlook.Recipient
Dim destfolder As Folders
Set myRecipient =
CreateObject("Outlook.Application").GetNamespace("MAPI").CreateRecipient("(e-mail address removed)")
'Import from
Set o_Out_Items = CreateObject("Outlook.Application") _
.GetNamespace("MAPI") _
.GetSharedDefaultFolder(myRecipient,
olFolderInbox).items
Set DestFolderPath = CreateObject("Outlook.Application") _
.GetNamespace("MAPI") _
.GetSharedDefaultFolder(myRecipient,
olFolderInbox) _
.destfolder
For Each o_Item In o_Out_Items
isithelpdesk = 0
'MsgBox o_Item.Subject
toname = o_Item.SenderName
'MsgBox toname
ssub = ""
scolleaguename = ""
sdepartment = ""
sextension = ""
sbigbox = ""
stype = ""
ssectionref = ""
swholesection = ""
slegal = ""
sitem = ""
scurrent = ""
sproposed = ""
sdatelaunched = ""
strmailbod = InvChars(o_Item.body)
ssub = o_Item.Subject
If ssub = "Big Box and Retail Rules & Standards Update" Then
isithelpdesk = 1
If InStr(1, strmailbod, "Colleague Name:
") > 0 Then
scolleaguename = ParseOrderDetails("Colleague
Name: ", strmailbod)
End If
If InStr(1, strmailbod, "Department: ")
strmailbod)
End If
If InStr(1, strmailbod, "Extension: ")
strmailbod)
End If
If InStr(1, strmailbod, "Big Box: ") >
0 Then
sbigbox = ParseOrderDetails("Big Box: ",
strmailbod)
End If
If InStr(1, strmailbod, "Type: ") > 0
Then
stype = ParseOrderDetails("Type: ", strmailbod)
End If
If InStr(1, strmailbod, "SectionRef: ")
strmailbod)
End If
If InStr(1, strmailbod, "Whole Section:
") > 0 Then
swholesection = ParseOrderDetails("Whole
Section: ", strmailbod)
End If
If InStr(1, strmailbod, "Legal: ") > 0
Then
slegal = ParseOrderDetails("Legal: ", strmailbod)
End If
If InStr(1, strmailbod, "Item: ") > 0
Then
sitem = ParseOrderDetails("Item: ", strmailbod)
End If
If InStr(1, strmailbod, "Current: ") >
0 Then
scurrent = ParseOrderDetails("Current: ",
strmailbod)
End If
If InStr(1, strmailbod, "Proposed: ") >
0 Then
sproposed = ParseOrderDetails("Proposed: ",
strmailbod)
End If
If InStr(1, strmailbod, "Date Launched:
") > 0 Then
sdatelaunched = ParseOrderDetails("Date
Launched: ", strmailbod)
End If
Set o_rs = CurrentDb.OpenRecordset("Select *
From t_Updates")
With o_rs
.AddNew
!ColleagueName = scolleaguename
!Department = sdepartment
!ContactNumber = sextension
!BigBox = sbigbox
!PolicyHowTo = stype
!SectionReference = ssectionref
!WholeSectionChange = swholesection
!LegislationLegalChange = slegal
!Item = sitem
!CurrentWording = scurrent
!ProposedWording = sproposed
!DateLaunchedToChain = sdatelaunched
.Update
.Close
End With
Set o_rs = Nothing
Else
End If
If sbigbox = "xxx" Then
Set destfolder = folder1
Else
End If
If sbigbox = "yyy" Then
Set destfolder = folder2
Else
End If
If isithelpdesk = 1 Then
o_Item.UnRead = False
o_Item.Move DestFolderPath
Set DestFolderPath = Nothing
Else
End If
Next
End Sub
email in a specified email folder and then parse's out certain data items and
imports them into an access DB, which works fine.
The bit i am struggling with is after that. I want the code to then move the
email into a folder depending on one of the data items in the email.
I am not sure if i have DIM'd the target folder correctly, can anyone else?
Thanks
Adrian
CODE:
Sub Checkmail()
Dim o_Out_Items As items
Dim DestFolderPath As Outlook.MAPIFolder
Dim o_Item As Variant
Dim o_items As MailItem
Dim strmailbod As String
Dim toname As String
Dim myRecipient As Outlook.Recipient
Dim destfolder As Folders
Set myRecipient =
CreateObject("Outlook.Application").GetNamespace("MAPI").CreateRecipient("(e-mail address removed)")
'Import from
Set o_Out_Items = CreateObject("Outlook.Application") _
.GetNamespace("MAPI") _
.GetSharedDefaultFolder(myRecipient,
olFolderInbox).items
Set DestFolderPath = CreateObject("Outlook.Application") _
.GetNamespace("MAPI") _
.GetSharedDefaultFolder(myRecipient,
olFolderInbox) _
.destfolder
For Each o_Item In o_Out_Items
isithelpdesk = 0
'MsgBox o_Item.Subject
toname = o_Item.SenderName
'MsgBox toname
ssub = ""
scolleaguename = ""
sdepartment = ""
sextension = ""
sbigbox = ""
stype = ""
ssectionref = ""
swholesection = ""
slegal = ""
sitem = ""
scurrent = ""
sproposed = ""
sdatelaunched = ""
strmailbod = InvChars(o_Item.body)
ssub = o_Item.Subject
If ssub = "Big Box and Retail Rules & Standards Update" Then
isithelpdesk = 1
If InStr(1, strmailbod, "Colleague Name:
") > 0 Then
scolleaguename = ParseOrderDetails("Colleague
Name: ", strmailbod)
End If
If InStr(1, strmailbod, "Department: ")
sdepartment = ParseOrderDetails("Department: ",0 Then
strmailbod)
End If
If InStr(1, strmailbod, "Extension: ")
sextension = ParseOrderDetails("Extension: ",0 Then
strmailbod)
End If
If InStr(1, strmailbod, "Big Box: ") >
0 Then
sbigbox = ParseOrderDetails("Big Box: ",
strmailbod)
End If
If InStr(1, strmailbod, "Type: ") > 0
Then
stype = ParseOrderDetails("Type: ", strmailbod)
End If
If InStr(1, strmailbod, "SectionRef: ")
ssectionref = ParseOrderDetails("SectionRef: ",0 Then
strmailbod)
End If
If InStr(1, strmailbod, "Whole Section:
") > 0 Then
swholesection = ParseOrderDetails("Whole
Section: ", strmailbod)
End If
If InStr(1, strmailbod, "Legal: ") > 0
Then
slegal = ParseOrderDetails("Legal: ", strmailbod)
End If
If InStr(1, strmailbod, "Item: ") > 0
Then
sitem = ParseOrderDetails("Item: ", strmailbod)
End If
If InStr(1, strmailbod, "Current: ") >
0 Then
scurrent = ParseOrderDetails("Current: ",
strmailbod)
End If
If InStr(1, strmailbod, "Proposed: ") >
0 Then
sproposed = ParseOrderDetails("Proposed: ",
strmailbod)
End If
If InStr(1, strmailbod, "Date Launched:
") > 0 Then
sdatelaunched = ParseOrderDetails("Date
Launched: ", strmailbod)
End If
Set o_rs = CurrentDb.OpenRecordset("Select *
From t_Updates")
With o_rs
.AddNew
!ColleagueName = scolleaguename
!Department = sdepartment
!ContactNumber = sextension
!BigBox = sbigbox
!PolicyHowTo = stype
!SectionReference = ssectionref
!WholeSectionChange = swholesection
!LegislationLegalChange = slegal
!Item = sitem
!CurrentWording = scurrent
!ProposedWording = sproposed
!DateLaunchedToChain = sdatelaunched
.Update
.Close
End With
Set o_rs = Nothing
Else
End If
If sbigbox = "xxx" Then
Set destfolder = folder1
Else
End If
If sbigbox = "yyy" Then
Set destfolder = folder2
Else
End If
If isithelpdesk = 1 Then
o_Item.UnRead = False
o_Item.Move DestFolderPath
Set DestFolderPath = Nothing
Else
End If
Next
End Sub