By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

Do not send email if no attachment

P: 41
Hi. Access 2003. The database stores contract information. I have a query for each person that is responsible for contracts. The query checks to see if there are reports due either this week, next week, or in three week. A report is created for each query but if the report has no data, it is not saved. I have a button on a form that will run code to automatically send each person their own report. If a person doesn't have a report, the email should not be sent and the routine should then run the next function. Code follows. The help I need is how to not send the email if there is no report. That part of the code is not working. Thanks in advance. Oh, in the sample code, the attachment is an Excel file while in the real world, it would be an Access report.

Expand|Select|Wrap|Line Numbers
  1. Function MailParametersNEW()
  2.  
  3. Dim objOutlook As Outlook.Application
  4. Dim objEmail As Outlook.MailItem
  5.  
  6. Set objOutlook = CreateObject("Outlook.application")
  7. Set objEmail = objOutlook.CreateItem(olMailItem)
  8.  
  9. With objEmail
  10.     .Importance = olImportanceHigh
  11.     .To = "bjo@propeople.org"
  12.   '  .CC = "jkt@propeople.org"
  13.    '  .BCC = "thb@XXX.org"
  14.     .Subject = "Access to Outlook testing code Tuesday"
  15.     .Body = "Testing code for Access to Outlook then to deal with no attachments"
  16.      On Error Resume Next
  17.     .Attachments.Add "G:\Accounting\CDImportNumbers\CDImportNumbers1.xls"
  18.     '.attachments.Add "c:\Path\to\the\next\file.txt"
  19.  
  20.  
  21.      If Attachments.Count = 0 Then
  22.      Cancel = True
  23.      Else: .Send
  24.      End If
  25.  
  26.  
  27.  
  28.  
  29.     .Send
  30.     '.ReadReceiptRequested
  31. End With
  32.  
  33.  
  34.  
  35.  
  36.  
  37.     Set objOutlook = Nothing
  38.     Set objEmail = Nothing
  39.  
  40.  
  41. 'Error_Handler:
  42. '    MsgBox Err & ": " & Err.Description
  43. '    Resume Exit_Here
  44.  
  45. End Function
Aug 7 '07 #1
Share this Question
Share on Google+
1 Reply


P: 41
Hi, I rewrote the code and figured it out. No need for help now. Thanks!
Aug 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.