Hi,
I have creatd a custom Outlook form with a few custom form fields.
When completed the form is sent to me and goes into my Inbox. This
works fine. Now Iam trying to write some code in Access to import
l;oop though my inbox and pick up all the usesr defined field data
from any messages froma specific subject. I have have mixed and
matched some code I found on the net however it doesn't seem to work
properly. problems I face are:
1. I have published this form in my firms org library however when the
code finds this msg (with the subject stated in the code) it still
prompts me to enable/disable macros. I can open this up directly from
outlook and not get the msg. Am not sure why this happens?
2. The code does work up to the extent that it will only pick up the
specific msg with the subject stated however it does not import the
users defined field data. I have made sure the field name stated does
indeed match etc. However still now joy. I can seem to figure out
why this is?
3. I now also however want to change it so that the code looks to
search a personal folder instead of my inbox. I will get hundreds of
responses which I want to set up a rule to filter to a persoanl folder
from there I want to run the code at the end of the week to pick up
all the data...without the macro warning!
The code i am using now is as below:
Sub ImportDataFromOutlook()
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("results")
Dim Ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.MailItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Dim inumreplies As Integer
Dim countitems As Integer
DoCmd.SetWarnings False
Set olns = Ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderInbox)
Set objItems = cf.Items
inumreplies = objItems.Count
countitems = 0
If inumreplies <> 0 Then
For i = 1 To inumreplies
If TypeName(objItems(i)) = "mailitem" Or objItems(i) = "MI
Group - Customer Satisfaction Survey" Then
countitems = countitems + 1
Set c = objItems(i)
rst.AddNew
rst!part1a = c.UserProperties("MIQ1")
rst!Date = Now
rst.Update
End If
Next i
rst.Close
DoCmd.SetWarnings True
MsgBox "Finished. " & countitems & " Mails imported from " & i -
1 & " mails in inbox"
Else
MsgBox "No Mails to import."
End If
End Sub
Any help and advise on this would be greatly appriciated!
Regards
Kunal