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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|