Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email from Access Formdoesnot work in Access 2007

Status
Not open for further replies.

Zepher2

Technical User
Dec 29, 2001
25
US
I do not know a lot about VBA coding. but here is my problem: I have had an Access 2003 DB and am using it to send emails to clients using fields from the form with code adapted from a tutorial found on this site.

I am trying to upgrade to Access 2007. If I use Access to open my old database in the email works fine.

I am creating a new database in 2007 and the same code returns a VBA error:

"Compile Error: User defined type not defined.

The VBA window highlights this line:

Dim objOutlook As Outlook.Application - as the offending code.

The entire code for the subroutine is:
Code:
Private Sub CCC_Email_Click()
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim email As String
Dim ref As String
Dim FirstName As String
Dim CaseNO As String
Dim hearingdate As String
Dim hearingtime As String
Dim bodyNotes1 As String
Dim bodyNotes2 As String
Dim bodyNotes3 As String

'**gathers information from your form.  this sets the string variable to your fields
email = Me!Client_email
ref = Me!LastName
FirstName = Me!FirstName
CaseNO = Me!Case_No
hearingdate = Me!Creditors_Exam_Date
hearingtime = Me!Creditors_Exam_Time
bodyNotes1 = “ text"
bodyNotes2 = "<P><font size = ""3"">some text.<P>The website address is: <a href=""[URL unfurl="true"]http://www.xxxxxxxxx.com"">xxxxxxxxxx.com</a>[/URL] <P>text- text. </html>"
bodyNotes3 = ""

'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'***creates and sends email
With objEmail
    .To = email
    .Subject = "Reminder to Complete Credit Counseling for " & ref & ", " & FirstName & "; " & "fromxx."
    .HTMLBody = bodyNotes1 & bodyNotes2
    .ReadReceiptRequested = True
    .Display 'sends the email in Outlook.  Change to DISPLAY if you want to be able to
      'modify or see what you have created before sending the email

'**closes outlook
'**objOutlook.Quit
'**Set objEmail = Nothing

Exit Sub
End Sub
Can anyone help me get this working?
Thanks in advance
 


Hi,

Please post MS Access questions in one of the many MS Access forums like forum705.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
User defined type not defined
You have to add a reference to the Outlook Object Library

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PVS


Thanks for your help. It works fine now that I added the reference.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top