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 ImportDataFromO utlook()
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenR ecordset("resul ts")
Dim Ol As New Outlook.Applica tion
Dim olns As Outlook.Namespa ce
Dim cf As Outlook.MAPIFol der
Dim c As Outlook.MailIte m
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserPro perty
Dim inumreplies As Integer
Dim countitems As Integer
DoCmd.SetWarnin gs False
Set olns = Ol.GetNamespace ("MAPI")
Set cf = olns.GetDefault Folder(olFolder Inbox)
Set objItems = cf.Items
inumreplies = objItems.Count
countitems = 0
If inumreplies <> 0 Then
For i = 1 To inumreplies
If TypeName(objIte ms(i)) = "mailitem" Or objItems(i) = "MI
Group - Customer Satisfaction Survey" Then
countitems = countitems + 1
Set c = objItems(i)
rst.AddNew
rst!part1a = c.UserPropertie s("MIQ1")
rst!Date = Now
rst.Update
End If
Next i
rst.Close
DoCmd.SetWarnin gs 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