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
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 .
Question: I'm using code from Chapter 18, the 'Working with Outlook 2010' section beginning on p. 672. My problem is incredibly basic: I've included the reference to the Outlook 14.0 Object Library; I've copied-n-pasted the code exactly as printed; the code compiles cleanly. But when I actually invoke any of the subs or functions here -- e.g. CreateEmailWithOutlook() on p. 675 -- the code halts at the first non-declaration line:
Code:
Set olMailItem = olApp.CreateItem(olMailItem)
To say this is frustrating understates the case. :)
Thank you so much for reading the Access 2010 Programmer's Reference and for your extremely kind words about the book! Also, I wanted to say thank you so much for posting your question here, because there is actually an error in the code in this chapter of the book!
You said:
Quote:
But when I actually invoke any of the subs or functions here -- e.g. CreateEmailWithOutlook() on p. 675 -- the code halts at the first non-declaration line...
You are completely correct and there are some typos in this code. The correct code from Page 675 should actually be:
Code:
Public Function CreateEmailWithOutlook( _
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 objMail As Object ' An Outlook Mail item
' Create a new email object
Set objMail = olApp.CreateItem(olMailItem)
' Add the To/Subject/Body to the message and display the message
With objMail
.To = MessageTo
.Subject = Subject
.Body = MessageBody
.Display ' To show the email message to the user
End With
' Release all object variables
Set objMail = Nothing
Set olApp = Nothing
End Function
And, although you didn't specifically mention it here, the code on page 676 should actually be:
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 objMail As Object ' An Outlook Mail item
' Create a new email object
Set objMail = olApp.CreateItem(olMailItem)
' Add the To/Subject/Body to the message and display the message
With objMail
.To = MessageTo
.Subject = Subject
.Body = MessageBody
.Send ' Send the message immediately
End With
' Release all object variables
Set objMail = Nothing
Set olApp = Nothing
End Function
This was actually one of my chapters in the book and I want to offer my deepest apologies for this mistake and thank you again for pointing it out so that we can get it fixed!
And if you have any other questions or need any other help here, please just let me know and I'll do what I can to help out.
*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
Thanks so much for getting back to me, Geoff. This is actually spectacularly good news, because it means I'm not crazy (ha). I've been doing Access VBA since 2.0 but am always being surprised by how little I still know, and I just assumed I'd completely overlooked something obvious. (Edit to add: actually, now that I'm looking at it, it IS obvious!)
Appreciate the help, and again, appreciate the book very much. Best of luck with it!
John
Last edited by JES; October 11th, 2011 at 01:36 PM.
The Following User Says Thank You to JES For This Useful Post:
Thank you again for the extremely kind words about the book and for reading it! Again my deepest apologies for such a blatant mistake on my part and it is horrible that this code mistake made it into the book, obvious or not. And really, my only hope is that the book has been helpful to you (aside from this problem)! And if you have any other questions about the book, please just let me know and I'll do what I can to help out!
*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
P.S. Geoff, the code from the book is reproduced verbatim in the Access 2010 Help documentation (and hence probably at the MS site) for the DoCmd.SendObject method. I have no idea how often they update that but it might be worth putting a bug in Microsoft's ear, too.
Thank you so much for the follow up here...some how I missed this note before?! Anyway, that is interesting, I did not realize the documentation on the Microsoft website was also incorrect. Do you have a link to the incorrect page on the Microsoft website? It would be a good idea to let them know if possible, but I'll need to know specifically which page you are referring to, because I'm not seeing it now (after a quick search).
Also, I wanted to thank you again for posting here and to let you know that we've fixed this error in our source code and have noted this problem on the errata page for the book at: http://www.wrox.com/WileyCDA/WroxTit...Cd-ERRATA.html. Thank you SO MUCH for pointing out this mistake and helping us to get it fixed for other readers in the future! If there is anything else we can do to help out with this issue, please just let me know!
And thank you again for reading the Microsoft Access 2010 Programmer's Reference book, we truly appreciate it!
*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->