Hello JES,
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.
Thanks,