Adding Outlook to Access 2003

Gkirkup

Registered User.
Local time
Yesterday, 19:21
Joined
Mar 6, 2007
Messages
628
I am using Access 2003 and want to add the Outlook library so that I can work with sending emails. My instructions say to use Tools / References but I don't see that in Access 2003. How do I add the Outlook library?

Robert
 
You need to open a code window (Alt + F11) and then go to Tools/References. Scroll down the list until you find the reference for Microsoft Outlook X.0 Object Library (the list is alphabetical). The X will be a number that is dependant on your version of Office (I think it's 10 for 2003).

attachment.php
 

Attachments

  • OutlookReference.jpg
    OutlookReference.jpg
    79.2 KB · Views: 270
OK, it came us as 11. Now I am getting a 'not defined; on this email code I am trying to use:

' Define some object variables for Outlook
Dim appOutlook As Outlook.Application 'Refers to Outlook's Application object.
Dim appOutlookMsg As Outlook.MailItem 'Refers to an Outlook e-mail message.
Dim appOutlookRecip As Outlook.Recipient 'Refers to an Outlook e-mail recipient.

Any suggestions?
Robert
 
Can you post all the code as well as the specific error message and which line is highlighted when when you debug?

Use the code tags when you post. It makes the code easier to read in the forum.
 
Will do, thanks. What are code tags? I am not familiar with that.

Robert
 
What are code tags? I am not familiar with that.

When you post sample code in the forum, it's best to copy/paste directly from you VBA window and then wrap the posted code with code tags. You can do this with the code tag button like in the image below (highlight your posted code then click the # button). Note you won't see the code tag button in the Quick Reply options, only the normal Reply options.

attachment.php


Or you can type the tags yourself at the beginning and the end of the posted code. The actual tags look like;

attachment.php


That way the indenting and spacing is preserved in your code which makes it much easier to read in the forum (like below).

Code:
Public Function fYearsMonths(dteStart As Date, dteEnd As Date) As String

    Dim i As Integer, intMonths As Integer, intYears As Integer
    Dim strMonths As String, strYears As String
    
    i = DateDiff("m", dteStart, dteEnd) + _
       (dteEnd < DateSerial(Year(dteEnd), Month(dteEnd), Day(dteStart)))
       
    intYears = Fix(i / 12)
    intMonths = i Mod 12
    
    strYears = IIf(intYears = 1, " year ", " years ")
    strMonths = IIf(intMonths = 1, " month", " months")
    
    fYearsMonths = IIf(intYears = 0, "", intYears & strYears) & intMonths & strMonths

End Function

If you don't use the code tags it can end up looking like below (blue font color added by me for clarity);

Public Function fYearsMonths(dteStart As Date, dteEnd As Date) As String
Dim i As Integer, intMonths As Integer, intYears As Integer
Dim strMonths As String, strYears As String
i = DateDiff("m", dteStart, dteEnd) + _
(dteEnd < DateSerial(Year(dteEnd), Month(dteEnd), Day(dteStart)))
intYears = Fix(i / 12)
intMonths = i Mod 12
strYears = IIf(intYears = 1, " year ", " years ")
strMonths = IIf(intMonths = 1, " month", " months")
fYearsMonths = IIf(intYears = 0, "", intYears & strYears) & intMonths & strMonths
End Function


which is more difficult to read. The difference isn't all that much with short blocks of code, but with longer procedures it makes a big difference. If you ever have a need to post a long block of code, many responders here won't even bother to try and read through it if you don't post it using code tags.
 

Attachments

  • CodeTag.jpg
    CodeTag.jpg
    86 KB · Views: 252
  • codetag2.jpg
    codetag2.jpg
    5.7 KB · Views: 242
Here is the code that I am having problems with:

Code:
[FONT=Arial]'The sub procedure below sends e-mail in response to a click on the Send button.[/FONT]
[FONT=Arial]Private Sub SendMessagesButton_Click()[/FONT]
[FONT=Arial][/FONT]
[FONT=Arial]'For Access, define some object variables and make connections.[/FONT]
[FONT=Arial]Dim myConnection As ADODB.Connection[/FONT]
[FONT=Arial]Set myConnection = CurrentProject.Connection[/FONT]
[FONT=Arial]Dim myRecordSet As New ADODB.Recordset[/FONT]
[FONT=Arial]myRecordSet.ActiveConnection = myConnection[/FONT]
[FONT=Arial][/FONT]
[FONT=Arial]'Define some object variables for Outlook[/FONT]
[FONT=Arial]Dim appOutlook As Outlook.Application 'Refers to Outlook's Application object.[/FONT]
[FONT=Arial]Dim appOutlookMsg As Outlook.MailItem 'Refers to an Outlook e-mail message.[/FONT]
[FONT=Arial]Dim appOutlookRecip As Outlook.Recipient 'Refers to an Outlook e-mail recipient.[/FONT]
[FONT=Arial][/FONT]
[FONT=Arial]'General variables.[/FONT]
[FONT=Arial]Dim mySQL As String, eMailAddress As String, whereClause As String[/FONT]
[FONT=Arial]Dim myMsg As String[/FONT]

The error message I am getting is 'Compile error: User-defined type'. I am getting that on the line: Dim appOutlook as Outlook.Application.
I do have Outlook selected on the references list.

Robert
 
Here is the code that I am having problems with:

Code:
[FONT=Arial][FONT=Arial]'The sub procedure below sends e-mail in response to a click on the Send button.[/FONT]
[FONT=Arial]Private Sub SendMessagesButton_Click()[/FONT]
 
[FONT=Arial]'For Access, define some object variables and make connections.[/FONT]
[FONT=Arial]Dim myConnection As ADODB.Connection[/FONT]
[FONT=Arial]Set myConnection = CurrentProject.Connection[/FONT]
[FONT=Arial]Dim myRecordSet As New ADODB.Recordset[/FONT]
[FONT=Arial]myRecordSet.ActiveConnection = myConnection[/FONT]
 
[FONT=Arial]'Define some object variables for Outlook[/FONT]
[FONT=Arial]Dim appOutlook As Outlook.Application 'Refers to Outlook's Application object.[/FONT]
[FONT=Arial]Dim appOutlookMsg As Outlook.MailItem 'Refers to an Outlook e-mail message.[/FONT]
[FONT=Arial]Dim appOutlookRecip As Outlook.Recipient 'Refers to an Outlook e-mail recipient.[/FONT]
 
[FONT=Arial]'General variables.[/FONT]
[FONT=Arial]Dim mySQL As String, eMailAddress As String, whereClause As String[/FONT]
[FONT=Arial]Dim myMsg As String[/FONT]
[/FONT]


The error message I am getting is 'Compile error: User-defined type'. I am getting that on the line: Dim appOutlook as Outlook.Application.
I do have Outlook selected on the references list.

Robert

Can you post a pic of your references list?
 
How do I make a pic of my references list to post here?

Robert
 
How do I make a pic of my references list to post here?

Robert

If you are on Windows Vista, or above, you can use the SnipTool if it has been included in your Accessories by your system admin.

If not on Windows Vista, or above, or you are and the SnipTool hasn't been enabled, then just open the references so they are showing and hit your PrtScn button to capture the screen and then paste it into Word and then upload the word document. If you do it in Word, make the margins as small as possible BEFORE pasting so it will keep as large of image as possible to see.
 
I don't have SnipTool on the server that hosts my application. Also I don't have PrtScrn on my Mac keyboard - I am running Windows 7 on an iMac.
So here is a list of my checked references:

Visual Basic for Applications
Microsoft Access 11.0 object library
OLE automation
Microsoft DAO 3.6 object library
Microsoft ActiveX data obbjects 2.5 library
Microsoft Windows common controls 6.0 (SP6)
Microsoft calendar control 11.0

Robert
 
I don't have SnipTool on the server that hosts my application. Also I don't have PrtScrn on my Mac keyboard - I am running Windows 7 on an iMac.
So here is a list of my checked references:

Visual Basic for Applications
Microsoft Access 11.0 object library
OLE automation
Microsoft DAO 3.6 object library
Microsoft ActiveX data obbjects 2.5 library
Microsoft Windows common controls 6.0 (SP6)
Microsoft calendar control 11.0

Robert
So, you said that you had Outlook checked.

Microsoft Outlook 11.0 Object Library

should be checked as well.
 
You are correct! I was confusing Access 11.0 with Outlook 11.0. It works now.

Robert
 

Users who are viewing this thread

Back
Top Bottom