Can't get this to work

F

Freehal04

Okay, here is the code I'm using. I had it working but for some reason now
all I get is an error message stating Compile error, user difined type not
defined. Before I was getting a different error. What's wrong?

Option Compare Database

Private Sub Detail_Click()
Option Explicit

Sub sbSendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message. Substitute
' your names here.
Set objOutlookRecip = .Recipients.Add("Douglas Clark")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = "This is a CDRL 10 day alert"
.Body = "You have a CDRL report due in 10 days. Please submit proper
documentation." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display

End If
Next
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing

End Sub
 
D

Douglas J. Steele

What line of code generates the Compile error?

If it's the declarations at the top of the routine, have you set a reference
to Outlook (under Tools | References in the VB Editor)?
 
F

Freehal04

I've set the reference to to Outlook, but when it won't tell me which line
has the problem. I don't know why it won't tell me which line is messed up,
it usually does, but for some reason it won't on this one.
 
D

Douglas J. Steele

Do a Compile on your application. (It's under the Debug menu while you're in
the Editor)
 
F

Freehal04

Okay, I did that and it said the compile error is 'Invalid inside procedure'
and it's highlighting the Option Explicit line of my code.
 
D

Douglas J. Steele

I didn't even notice that!

Move that line to the beginning of the file, either just before or just
after Option Compare Database (it shouldn't matter which)
 
J

JimB

You never ended your Detail_Click() subroutine. Maybe you accidentally
deleted the end sub statement. Your trying to start a new subroutine before
ending the other one.

Jim B.
 

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