Kath Pelletti
KP at sdsonline.net
Mon Mar 14 21:42:41 CST 2005
Thanks Darren - code is below: Error is 'automation error - module not found' on line: Set nms = appOutlook.getnamespace ("MAPI") Kath Public Function ProcessMailMessagesInFolder() 'Adapted by K Pelletti from code from Helen Feddema 3-28-2002 Dim strerrormsg As String On Error GoTo Err_Handler Dim appOutlook As New Outlook.Application Dim nms As Outlook.NameSpace Dim fld As Outlook.MAPIFolder Dim myfld As Outlook.MAPIFolder 'itm declared as object because a folder can contain different 'types of objects Dim itm As Object Dim msg As Outlook.MailItem Dim strMessage As String Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim strsql As String Dim prj As Object Dim lngItemCount As Long Dim IntFolderNo As Integer Dim IntTotalNoFoldersInInbox As Integer Dim IntNoMailItems As Integer Dim BoolFolderFound As Boolean BoolFolderFound = False Set nms = appOutlook.GetNamespace("MAPI") 'CRASHES HERE Set fld = nms.GetDefaultFolder(olFolderInbox) IntFolderNo = 0 IntTotalNoFoldersInInbox = 0 IntNoMailItems = 0 IntTotalNoFoldersInInbox = fld.Folders.Count ' MsgBox ("Inbox has: " & fld.Folders.Count & "subfolders.") Do Until IntFolderNo = IntTotalNoFoldersInInbox ' Inner loop. IntFolderNo = IntFolderNo + 1 Set myfld = fld.Folders(IntFolderNo) If myfld.Name = "Customer Inquiries" Then BoolFolderFound = True IntNoMailItems = myfld.Items.Count ' MsgBox ("No messages is: " & IntNoMailItems) Exit Do End If Loop If BoolFolderFound = False Then MsgBox ("Unable to find the Customer Inquiries Folder in Outlook." & vbCrLf & vbCrLf & "(The folder should be a subfolder of inbox.)"), , "Hudsons Database" GoTo Normal_exit End If If myfld Is Nothing Then GoTo Err_Handler End If Debug.Print "Folder default item type: " & myfld.DefaultItemType If myfld.DefaultItemType <> olMailItem Then MsgBox "Folder does not contain mail messages; Exiting", , "Importing Mail" GoTo Normal_exit End If lngItemCount = myfld.Items.Count ' Debug.Print "Number of messages in folder: " _ ' & lngItemCount If lngItemCount = 0 Then MsgBox ("There are no mail messages in the Customer Inquiries folder."), , "Hudsons Database" GoTo Normal_exit End If 'Process items in selected folder strsql = "DELETE * FROM tblOutlookMail" DoCmd.SetWarnings False DoCmd.RunSQL strsql Set dbs = CurrentDb Set rst = dbs.OpenRecordset("tblOutlookMail") For Each itm In myfld.Items If itm.Class = olMail Then Set msg = itm With rst .AddNew !Subject = msg.Subject !Body = msg.Body !CC = msg.CC !BCC = msg.BCC !Sent = msg.SentOn !FromName = msg.SenderName .Update End With End If Next itm rst.Close Set prj = Application.CurrentProject If prj.AllForms("frmOutlookMail").IsLoaded = True Then Forms("frmOutlookMail").Requery Else DoCmd.OpenForm "frmOutlookMail", , , , , acDialog End If 'Forms("frmOutlookMail").SetFocus Normal_exit: ' MsgBox ("No of new mail messages: " & IntNoMailItems), , "Mail Import" Exit Function Err_Handler: MsgBox "Error: [" & Err.Number & "] " & IIf(Len(strerrormsg) > 0, strerrormsg, Err.Description), vbCritical, "Error Message" hCursor = CursorID RetVal = SetCursor(hCursor) Resume Normal_exit End Function ----- Original Message ----- From: Darren DICK To: 'Access Developers discussion and problem solving' Sent: Tuesday, March 15, 2005 2:36 PM Subject: RE: [AccessD] Urgent - missing Outllok in Refs Hi Kath I posted to Outlook Dev mail group re this one and they want to know What is the error message? How are you instantiating the objOutlook? Can I see the code? Many thanks Darren -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Kath Pelletti Sent: Tuesday, 15 March 2005 12:42 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Urgent - missing Outllok in Refs OK - got it. I can see that they aren't installed and will now get them couriered over from the other side of town.... Thanks - I could have wasted a lot more time on this Kath ----- Original Message ----- From: Charlotte Foust To: Access Developers discussion and problem solving Sent: Tuesday, March 15, 2005 12:20 PM Subject: RE: [AccessD] Urgent - missing Outllok in Refs Yup, that's the missing CDO, Collaborative Data Objects. When you install Office, you have to drill down in the Outlook part and check the CDO item to include it in the install. Otherwise, no MAPI calls. You can ONLY install CDO using a custom installation, not the default. Charlotte Foust -----Original Message----- From: Kath Pelletti [mailto:KP at sdsonline.net] Sent: Monday, March 14, 2005 5:11 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Urgent - missing Outllok in Refs Hi Charlotte - yes Outlook is installed. I have removed the old ref to Outlook 9 and then gone back thru' the ref list and found Outlook 11 and ticked that. But now when I use the function which looks for Outlook the code falls over with 'Automation error - the specified module cannot be found' Line where crash happens: Set nms = appOutlook.getnamespace ("MAPI") NB: This code has always worked until she has had Office re-installed (same version - 2000). I have had a look at the install and it seems fine - what else can I check? What is the CDO? THanks - Kath ----- Original Message ----- From: Charlotte Foust To: Access Developers discussion and problem solving Sent: Tuesday, March 15, 2005 11:55 AM Subject: RE: [AccessD] Urgent - missing Outllok in Refs Is Outlook installed on the machine? Even if it is, you can't use it from Access unless the CDO was installed as well. It isn't by default, but you can do a custom reinstall and add it. Charlotte Foust -----Original Message----- From: Kath Pelletti [mailto:KP at sdsonline.net] Sent: Monday, March 14, 2005 4:49 PM To: AccessD at databaseadvisors.com Subject: [AccessD] Urgent - missing Outllok in Refs Hi all - quick question as I am out with a client - She has a new laptop so an existing app has been re-installed - Outllok functions in Access mdb no longr working - I went into vba and expected to find a missing reference in the References window - but Outlook isnt there at all - what isn;t installed? THanks ______________________________________________ Kath Pelletti Software Design & Solutions Pty Ltd. Ph: 9505-6714 Fax: 9505-6430 KP at SDSOnline.net -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com