Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 February 17th, 2004, 11:11 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default email from a form

I have the procedure below to email a patient using records from a form attached to a table.

Everything works fine up to the point where it opens Outlook Express and populate the fields. However, the mail is not being sent even though everything is the way it should be.

When I click the Send button in Outlook the email disappears from the screen. The email is just not being sent.

Any suggestion.

   Dim patEmail As String ' email of patient from tblPatient
   Dim patName As String 'patient name from tblPatient
   Dim objOutlook As Outlook.Application
   Dim objOutlookMsg As Outlook.MailItem
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment
   Dim apTime As Variant 'appointmrnt time taken from form
   Dim apDate As Date ' appointment date taken form form

    'Get email address and patient name from tblPatient
    Set rst = New ADODB.Recordset
    Set cnn = CurrentProject.Connection
    strSQL = "SELECT Email, FName, LName, MI FROM tblPatient " & _
    "WHERE PatientID = " & Forms!frmAppointment!frmAppointmentSub!PatientID
    rst.Open strSQL, cnn, adOpenKeyset, , adCmdText

    patEmail = rst!Email
    patName = rst!FName & " " & rst!MI & " " & rst!LName
    apTime = Format(Forms!frmAppointment!frmAppointmentSub!Appt Time, "h:mm AM/PM")
    apDate = Forms!frmAppointment!ApptDay


   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")


        ' Create the e-mail message
                Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
                patEmail = rst!Email

                       With objOutlookMsg
                                      ' Add the To recipient(s) to the e-mail message
                                      Set objOutlookRecip = .Recipients.Add(patEmail)
                                      objOutlookRecip.Type = olTo

                                      ' Set the Subject, Body, and Importance of the e-mail message.
                                      .Subject = "Dental Appointment"
                                      .Body = "Dear " & patName & ":" & _
                                      vbCr & vbCr & "This is a you of you dental appointment scheduled for " & Format(apDate, "dddd, mmmm d, yyyy") & " at " & apTime & "." & _
                                       vbCr & vbCr & "If you are unable to keep the appointment please call me at (800) 555 8270" & _
                                       vbCr & vbCr & "Sharon"
                                      .Importance = olImportanceHigh 'High importance
                                      .Display
                                     ' .Send
                    End With

   rst.Close
   Set rst = Nothing
Reply With Quote
  #2 (permalink)  
Old February 18th, 2004, 04:51 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Remove the apostrophe from the line that is
Code:
'.send
. Be careful when testeing or people are going to receive surprise emails
As a side note sending data like this via email seems a little risky.

--

Joe
Reply With Quote
  #3 (permalink)  
Old February 18th, 2004, 06:31 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That does not seem to be the solution. It seems that when the apostrophe is removed the email is sent directly and is not displayed on the screen.

Even when I remove it it still does not send.

Thanks for any other comments.
Reply With Quote
  #4 (permalink)  
Old February 18th, 2004, 06:49 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by stoneman
 That does not seem to be the solution. It seems that when the apostrophe is removed the email is sent directly and is not displayed on the screen.

Even when I remove it it still does not send.

Thanks for any other comments.
These two statements seem to contradict each other. If you remove the apostrophe does it send? If it does but you want it to wait before sending you need to add some waiting code of maybe a prompt box asking if they now wish to send.

--

Joe
Reply With Quote
  #5 (permalink)  
Old February 18th, 2004, 09:19 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe:

If I keep the apostrophe Outlook opens and displays the email. You cilck send form Outlook to manually send the email. When I do this Outlook closes and the email is not sent because it does not show up in my inbox.

Removing the apostrophe does not open Outlook and the email is also not send.

Hope that clarify that.
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
Form email Questions John10Yes ASP.NET 2.0 Basics 4 September 15th, 2006 10:58 AM
sending email from a form x_ray ASP.NET 1.0 and 1.1 Basics 5 February 22nd, 2006 02:58 PM
Form to Email gateway starknaked Flash (all versions) 0 March 16th, 2005 01:12 AM



All times are GMT -4. The time now is 06:52 AM.


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