Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Access 2010 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2010 Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Jerry Dennison; ISBN: 978-0-470-59166-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2010 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 20th, 2012, 10:54 AM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Question Page 675- Creating an E-mail ?

The following is the code I have used from this page in the book. I have provided the variable values, ( which I have assumed are the only things which need to be changed ) Tha call procedure and my parameters are also listed. However, I get the following error message, highlighting the line 'Set olMailItem = olApp.CreateItem(olMailItem)' - "Object variable or With block variable not set. " Any ideas ?
Code:
 
Public Function SendEmailWithOutlook(MessageTo As String, Subject As String, MessageBody As String)
' Define app variable and get Outlook using the "New" keyword
Dim olApp As New Outlook.Application
Dim olMailItem As Outlook.MailItem ' An Outlook mail item
' Create a new e-mail object
Set olMailItem = olApp.CreateItem(olMailItem)
' Add the To/Subject/Body to the message and display the message
With olMailItem
    .To = MessageTo
    .Subject = Subject
    .Body = MessageBody
    .Send    ' Send the message immediately
End With
' Release all object variables
Set olMailItem = Nothing
Set olApp = Nothing
End Function
Code:
 
Call SendEmailWithOutlook("Amera.Jan@advocacyforall.org.uk", "Test e-mail for AfAIS Database Referrals", "Referral No. 1FB060612 was referred 14 days ago. Status remains unassessed. Thank you")
Reply With Quote
  #2 (permalink)  
Old June 20th, 2012, 02:43 PM
Authorized User
Points: 380, Level: 6
Points: 380, Level: 6 Points: 380, Level: 6 Points: 380, Level: 6
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi again,

It looks like it's a case of bad variable naming, the variable olMailItem conflicts with the constant of the same name, so just rename the variable to objMailItem in all instances except where the constant olMailItem is used in the CreateItem method.

That is the code that creates the mail item should be:
Set objMailItem = olApp.CreateItem(olMailItem)

You could even just change the constant used to 0 instead and it will work, but it's better to use the constant rather than hard code the value.

I would change the olApp to objApp or objOutlook too, but it's unnecessary.

HTH.

Malc.
Reply With Quote
  #3 (permalink)  
Old June 20th, 2012, 03:16 PM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Question

Thank you. As you can see I just literally copied the code in the book into my program. Would these anomalies be obvious, if I had downloaded the relevant code for this ? Or is the example, 'badly' coded ?
Reply With Quote
  #4 (permalink)  
Old June 20th, 2012, 03:55 PM
Authorized User
Points: 380, Level: 6
Points: 380, Level: 6 Points: 380, Level: 6 Points: 380, Level: 6
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi,

I'm not sure if the downloaded code is any different. I have this book too and would say the example is badly coded considering it does not work! However, the authors of this book are extremely clever people and Access experts, so this is more likely a typo that has been introduced during printing.

Anomalies will only be obvious if you fully understand the context of the code anyway!

Malc.
Reply With Quote
  #5 (permalink)  
Old June 21st, 2012, 05:57 AM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default

I take your point. I'm about to make the changes you suggest.
Reply With Quote
  #6 (permalink)  
Old June 21st, 2012, 06:14 AM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default

It seems to cause an error on the '.Send' instruction of the routine. I substituted, '.Display' for '.Send', as in the example on the previous page, and this tries to open Outlook ( on my computer ) I'm not familiar with OUTLOOK as a program, so I'm not sure how to get round this.
Reply With Quote
  #7 (permalink)  
Old June 21st, 2012, 07:17 AM
Authorized User
Points: 380, Level: 6
Points: 380, Level: 6 Points: 380, Level: 6 Points: 380, Level: 6
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi,

That is the whole point of this code, to open Outlook, create an email message and send it. If you don't have Outlook set up as an email client then it will not work!

Which email client do you use? You should probably try using the DoCmd.SendObject Method instead, read about it in Help.

Malc.
Reply With Quote
  #8 (permalink)  
Old June 21st, 2012, 10:06 AM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default

Thank you for your advice. I will look into it.
Reply With Quote
  #9 (permalink)  
Old June 22nd, 2012, 09:05 AM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default

We are using OUTLOOK as the e-mail client. I am on a 'remote' computer, NOT part of the organisations's network. Does this matter, and if so, should DoCmd.SendObject, forward the e-mail over the internet to them ?
Reply With Quote
  #10 (permalink)  
Old June 22nd, 2012, 09:45 AM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default

I have coded using the 'DoCmd.SendObject', but it is asking that an OUTLOOK account be set up, and password isn't valid ? Are you able to help ? I'll use this method if it works ( as it's only one line of code ! ) Is it to do with the type of 'connectedness' or otherwise, of the sender and the recipient ? I'm trying to send a test e-mail from a public computer, to my organisation who I'm designing for ( using an event trigger in my VBA ). Thank you if you can elucidate in any way.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 2 - page 41 problem creating the page.. jorjiana BOOK: Beginning Oracle Application Express ISBN: 9780470388372 2 August 22nd, 2009 04:25 AM
Creating E-Mail Messages shoe1189 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 February 17th, 2009 11:07 AM
Creating E-Mail Messages janla2112 ASP.NET 3.5 Basics 3 October 26th, 2008 01:23 PM
P 675 addressList exercise ChristopherFromBC VB.NET 2002/2003 Basics 1 May 31st, 2007 03:55 PM
Mail from ASP page vin_0x1 Classic ASP Professional 2 September 16th, 2006 10:15 PM



All times are GMT -4. The time now is 09:37 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.