A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can't get this to work



 
 
Thread Tools Display Modes
  #1  
Old November 28th, 2006, 05:14 PM posted to microsoft.public.access.gettingstarted
Freehal04
external usenet poster
 
Posts: 124
Default Can't get this to work

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

  #2  
Old November 28th, 2006, 05:22 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Can't get this to work

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)?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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



  #3  
Old November 28th, 2006, 05:38 PM posted to microsoft.public.access.gettingstarted
Freehal04
external usenet poster
 
Posts: 124
Default Can't get this to work

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.

"Douglas J. Steele" wrote:

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)?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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




  #4  
Old November 28th, 2006, 05:58 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Can't get this to work

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

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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.

"Douglas J. Steele" wrote:

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)?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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






  #5  
Old November 28th, 2006, 06:12 PM posted to microsoft.public.access.gettingstarted
Freehal04
external usenet poster
 
Posts: 124
Default Can't get this to work

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.

"Douglas J. Steele" wrote:

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

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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.

"Douglas J. Steele" wrote:

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)?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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







  #6  
Old November 28th, 2006, 06:36 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Can't get this to work

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)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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.

"Douglas J. Steele" wrote:

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

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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.

"Douglas J. Steele" wrote:

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)?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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









  #7  
Old November 28th, 2006, 06:54 PM posted to microsoft.public.access.gettingstarted
JimB
external usenet poster
 
Posts: 78
Default Can't get this to work

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.

"Freehal04" wrote:

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.

"Douglas J. Steele" wrote:

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

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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.

"Douglas J. Steele" wrote:

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)?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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







  #8  
Old November 30th, 2006, 10:43 PM posted to microsoft.public.access.gettingstarted
Freehal04
external usenet poster
 
Posts: 124
Default Can't get this to work

Right, I've got it to work. Thaks for your help. One more thing. Is there
a way to make this emailer work without access open and running? I want it
to have an IF THEN statement, like If due date is today, then send email.
I'm thinking the db has to be at least open for it to do the process.
Comments?

"Douglas J. Steele" wrote:

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)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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.

"Douglas J. Steele" wrote:

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

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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.

"Douglas J. Steele" wrote:

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)?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Freehal04" wrote in message
...
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










 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.