Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Message is gone after choosing to preview using SendObject 1

Status
Not open for further replies.

saigonvietnam

Programmer
Dec 6, 2004
9
0
0
US
Hi All, I'm trying to send email with the default message through a form using Access 2003. User will choose whether or not to preview the message before seding. If the user choose to send w/o previewing, the default message will be sent OK. However, if the user choose to preview the message first before sending, the email will be opened for editing but the default message is gone.
Would anyone know what I have done wrong. Here is the code:

Private Sub cmdSubmit_Click()
On Error GoTo Err_Mail_Cancel

Dim intSeeOutlook As Integer
Dim bOption As Boolean
intSeeOutlook = MsgBox("Preview e-mail message?", _
vbYesNo, Me.cboCaseName & Me.Caption)

If intSeeOutlook = vbNo Then
bOption = False
Else
bOption = True
End If

DoCmd.SendObject acSendNoObject, , , Me.txtAttorneyEmail, , , _
Me.cboCaseName, "This will be the default message", bOption

DoCmd.GoToRecord , , acNewRec
Exit_cmdSubmit_Click:
Exit Sub

Err_Mail_Cancel:
Me.Undo
MsgBox ("Your Mail has been canceled!")

End Sub


Thanks!
 
does your send button on the preview form have the default message?

Check to make sure your using the same code on the preview form as on the other form
 
Hi mygmat123,

It's not a preview "Access Form", instead it is an Outlook newly email Item. Exactly the same as you try to "Compose" a new email.

I'm using only one form which has one button (cmd_Submit). After user click submit button, the "Preview Comfirmation" dialog box is opened by using MsgBox. If Click "Yes", Access will open Outlook window with the newly email Item. If Click "No" Access will send the email w/o openning the email Item.

No matter what user choose, it always execute the same code in the cmd_Submit_Click() which is:

DoCmd.SendObject acSendNoObject, , , Me.txtAttorneyEmail, , , _
Me.cboCaseName, "This will be the default message", bOption

Thanks!
 
Try this........

Private Sub cmdSubmit_Click()
On Error GoTo Err_Mail_Cancel

Dim intSeeOutlook As Integer
Dim intOption As integer
intSeeOutlook = MsgBox("Preview e-mail message?", _
vbYesNo, Me.cboCaseName & Me.Caption)

If 7 = intseeOutlook Then
intOption = 0
Else
intOption = -1
End If

DoCmd.SendObject(acSendNoObject, , , Me.txtAttorneyEmail, , , _
Me.cboCaseName, "This will be the default message", intOption)

DoCmd.GoToRecord , , acNewRec
Exit_cmdSubmit_Click:
Exit Sub

Err_Mail_Cancel:
Me.Undo
MsgBox ("Your Mail has been canceled!")

End Sub
 
Another way - you need to add the outlook reference to your library:

Dim intSeeOutlook As Integer
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim myBodyText As String
Dim Recipient As String

Subjectline = "The Email Subject"
Recipient = "JimBob@anywhere.com"
myBodyText = "Standard Comments"

intSeeOutlook = MsgBox("You are sending a message to " & Recipient & "." & vbLf & vbLf & _
"The Subject Line is " & Subjectline & "." & vbLf & vbLf & _
"The Message is " & myBodyText & "." & vbLf & vbLf & _
"Do you wish to send the message?", vbYesNo)


Select Case intSeeOutlook

Case Is = vbYes


Set MyOutlook = New Outlook.Application


Set MyMail = MyOutlook.CreateItem(olMailItem)
MyMail.To = "ddavis@bibb.com"
MyMail.Subject = "Attorney Case Name"
MyMail.Body = "This will be the default Message"


MyMail.Send

'Update your record

Case Is = vbNo

MsgBox "Ok, Cancelling Send"




End Select
 
mygmat123, Thanks! .. However, the statement:

DoCmd.SendObject(acSendNoObject, , , Me.txtAttorneyEmail, , , _
Me.cboCaseName, "This will be the default message", intOption)
Prompt an error: "Compile Error: Expected: ="
I did try this way before but it didn't seem to pass the compiler.

dRahme, Your solution is working fine with preview the message. Sorry! I forgot to mention that the user also have an ability to edit the message as well. Hence, we have to use the code:

MyMail.Display ' (or maybe not?)

Then, I run into the problem of checking to see whether or not the user actually send the message or hit the "X" cancel button after the message has been open to display on an Outlook window.

Thanks all! I'm really appreciated your help.

 
Hi, was a little abrupt yesterday - had some real work to do. The way I handle this is to build a form where the user inputs their message and the other pertinent information. When they've finished typing their message they click a submit button, a confirmation is asked for and the email is sent using information captured from the form.

I don't know how one would detect that the Outlook button has actually been depressed. Perhaps someone else knows how to do that.

There is some software out there that bypasses the Outlook security which asks for confirmation before sending but it has to be installed on each user's machine. Use something like that and you would not have to detect a button click in Access. I think there are several links to that in the massive thread concerning emailing, which incidentally covers just about everything regarding email, Access and Outlook.
 
Hi! dRahme, two days ago I actually did the same as you said (create a textbox for message on the form). Thanks! the credit is to you. As I read and play with your MsgBox comfirmation, the idea just poped up in my head. I'm happy with this alternative solution.

Again Thanks! A Star is for you, also.

Sincerely,

Linhsy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top