G
Guest
I want to loop through all "User properties".index and use
Name and Value to name the columns in table tblInbox and insert the value in
that column of this table dynamically. I have over 200 user-defined OL fields
to import so there may be too much coding for each item.
So, can I loop in .Index and use .Name and .Value to do this ?
My snippet is below.
Any suggestions.
Thanks in advance
Chuck
My Snippet is as follows:
Sub ImportInboxFromOutlook()
On Error GoTo Error_Handler
Dim strFName, strLName As String
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblInbox")
Dim MyPos, importcount As Integer
' Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim m As Outlook.MailItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Dim objImportedFolder As MAPIFolder ' Move action
Dim iNumMsgs As Integer
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderInbox)
Set objItems = cf.Items
'Screen.MousePointer = 11 'Make hourglass
'On Error GoTo ErrorHandler_Folder 'if the folder is not available then...
Set objImportedFolder = cf.Folders("21st Century") 'Move
action
On Error GoTo Error_Handler 'reset error once past 'folder' check
importcount = 0
iNumMsgs = objItems.Count
' MsgBox "iNumMsgs" & ": " & iNumMsgs, vbOKOnly
If iNumMsgs > 0 Then
For i = 0 To iNumMsgs
If TypeName(objItems(i)) = "MailItem" Then
Set m = objItems(i)
MyPos = InStr(1, m.Subject, "21st Century Grant") 'Is this mail
item for the 21st Century grant
If (MyPos) > 0 Then
rst.AddNew
rst!SenderName = m.SenderName
rst!Subject = m.Subject
rst!SentOn = m.SentOn
rst!To = m.To
' Get user-defined fields
strFName = m.UserProperties("NameFirst")
strLName = m.UserProperties("NameLast")
rst!NameLast = m.UserProperties("NameLast")
rst!StudentID = m.UserProperties("txtStudentID")
Name and Value to name the columns in table tblInbox and insert the value in
that column of this table dynamically. I have over 200 user-defined OL fields
to import so there may be too much coding for each item.
So, can I loop in .Index and use .Name and .Value to do this ?
My snippet is below.
Any suggestions.
Thanks in advance
Chuck
My Snippet is as follows:
Sub ImportInboxFromOutlook()
On Error GoTo Error_Handler
Dim strFName, strLName As String
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblInbox")
Dim MyPos, importcount As Integer
' Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim m As Outlook.MailItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Dim objImportedFolder As MAPIFolder ' Move action
Dim iNumMsgs As Integer
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderInbox)
Set objItems = cf.Items
'Screen.MousePointer = 11 'Make hourglass
'On Error GoTo ErrorHandler_Folder 'if the folder is not available then...
Set objImportedFolder = cf.Folders("21st Century") 'Move
action
On Error GoTo Error_Handler 'reset error once past 'folder' check
importcount = 0
iNumMsgs = objItems.Count
' MsgBox "iNumMsgs" & ": " & iNumMsgs, vbOKOnly
If iNumMsgs > 0 Then
For i = 0 To iNumMsgs
If TypeName(objItems(i)) = "MailItem" Then
Set m = objItems(i)
MyPos = InStr(1, m.Subject, "21st Century Grant") 'Is this mail
item for the 21st Century grant
If (MyPos) > 0 Then
rst.AddNew
rst!SenderName = m.SenderName
rst!Subject = m.Subject
rst!SentOn = m.SentOn
rst!To = m.To
' Get user-defined fields
strFName = m.UserProperties("NameFirst")
strLName = m.UserProperties("NameLast")
rst!NameLast = m.UserProperties("NameLast")
rst!StudentID = m.UserProperties("txtStudentID")