issues with migrating to office 365 and outlook emailing (1 Viewer)

Gamerlon

New member
Local time
Today, 16:46
Joined
May 9, 2022
Messages
2
Hi all,

I've recently changed my PC to office 365 and have a few access program with sends emails from.
With the change, i struggle to get emails to send with the office changes and was wondering if anyone has any guidance?

with my old office and office object 15.0 changed to 16.0
access if stopping on the inital code with a compile error "user-defined type not defined" when dim on the outlook.


Public Function SendEMail()

Dim db As DAO.Database
Dim MailList As DAO.Recordset
===> Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim MyAttach As String
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:46
Joined
Aug 30, 2003
Messages
35,714
In the VBA editor go into Tools/References. You probably need to change the Outlook reference.
 

Gamerlon

New member
Local time
Today, 16:46
Joined
May 9, 2022
Messages
2
In the VBA editor go into Tools/References. You probably need to change the Outlook reference.
it only allows object 16.0 to be available. Are you suggesting to find 15.0?
 

strive4peace

AWF VIP
Local time
Today, 01:46
Joined
Apr 3, 2020
Messages
861
hi @Gamerlon

re: error message: user-defined type not defined

> Dim MyMail As Outlook.MailItem

this requires an a reference, as Paul ( @pbaldy ) told you how to do with Tools/References

However, if you simply want to send an email using Outlook from Access, without specifying any particular references, you can use code something like this:

Rich (BB code):
Sub EmailOutlook()
'strive4peace

   On Error GoTo Proc_Err

   'use early binding to develop
'   Dim appOut As Outlook.Application _
      ,oMsg As Outlook.MailItem

   'use late binding to deploy
   Dim appOut As Object _
      ,oMsg As Object

   Dim sPathFileAttachment As String _
      ,sSubject As String _
      ,sBody As String _
      ,sMailTo As String

   'this information could be passed as parameters
   sMailTo =  "someone@somewhere.com"
   sSubject =  "My subject line"
   sBody =  "My message"
   sPathFileAttachment =  "c:\path\file.ext" 'or whatever this is

   Set appOut = CreateObject( "Outlook.Application")
   Set oMsg = appOut.CreateItem(0)  '0=olMailItem

   With oMsg
      '.Importance = olImportanceHigh
      .To = sMailTo
      '.CC = "cc email address"
      '.BCC = "cc email address"
      .Subject = sSubject
      .Body = sBody
      If sPathFileAttachment <>  "" Then
         .Attachments.Add sPathFileAttachment
      End If
   
      ' If you want to edit before sending
      .Display
      'otherwise, to just send without looking...
      '.Send
   End With

Proc_Exit:
   On Error Resume Next
   'release object variables
   Set appOut = Nothing
   Set oMsg = Nothing
   Exit Sub

Proc_Err:
   MsgBox Err.Description,,_
        "ERROR " & Err.Number _
        &  "   EmailOutlook"

   Resume Proc_Exit
   Resume
End Sub
 

Users who are viewing this thread

Top Bottom