Compiler error

L

Lodewijk Olthof

On my form I have a button to email a document from disc. The code behind
this button is:

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.To = (e-mail address removed)
.Attachments.Add strDocument
.Send
End With

When I push the button, I get the following (translated) error message:
(Compileerfout: Een door de gebruiker gedefinieerd gegevenstype is niet
gedefinieerd)
A by the user defined gegevenstype (I don't know the right word, but it's
the type for boolean, string, etc.) is not defined.

What do I have to do to correct this
 
J

Jim/Chris

I have seen quite a bit of code for sending email. I have
tried many of them. The one below( I have it stored as a
function) has been the most reliable for me with MS
Outlook. Also I am able to pull from an open form the
recipient, subject, text and attachment(s).

Good Luck

Jim

Function SendEMail()
Dim strTo As String, strSubject As String, _
varBody As Variant, strCC As String, _
strBCC As String, strAttachment As String,
strAttachment1 As String

strTo = "email address"
strSubject = "put subject here"
varBody = "put message for body here"
' Add more strattachments if needed and modify IF statement
' below
strAttachment = "attachment1"
strAttachment1 = "attachment2"
'Start Outlook
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

'Logon
Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon

'Send a message
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
'Fill Out and Send Message
olMail.To = strTo
olMail.CC = strCC
olMail.BCC = strBCC
olMail.Subject = strSubject
olMail.Body = varBody
' Modify these statements if more attachmewnts are needed
If Len(strAttachment) <> 0 Then
olMail.Attachments.Add (strAttachment)
If Len(strAttachment1) <> 0 Then
olMail.Attachments.Add (strAttachment1)
End If
End If
olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing

End Function
 
L

Lodewijk Olthof

Sorry, that's obviously interesting to know.

The error occurs on the line with: Dim objOutlook As Outlook.Application
 
L

Lodewijk Olthof

Jim,

With your code I also get the error message on the line
Dim olApp As Outlook.Application

Lodewijk
 
K

Ken Snell

I am guessing that you don't have a reference set to Outlook.

However, by using CreateObject, you don't need to Dim objOutlook that way.
Replace that line of code with this:

Dim objOutlook As Object


That will use late binding and you won't need a reference to be set.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top