PDA

View Full Version : Can you tell me why it sends two emails?



hibiscus27
04-19-2007, 12:14 PM
Hello

I have the following code attached to a button. Once clicked it is supposed to open up an outlook email message.

I'm getting notices from users that when they click on the button, two messages end up being emailed instead of 1. Can you take a look at tell me why? Thanks!!!

'***** Open a new email with project attached to send to next person
Private Sub btnSendNext_Click()
MsgBox "On the next screen, you will see a mail message created with the approval request attached." & Chr(10) & _
"Please address it to the Saltillo Quality Engineer and click the send button."
Application.Dialogs(xlDialogSendMail).Show arg1:="", arg2:="Process Approval Request " & ActiveSheet.Range("B12").Value & " - form needs review. Sign and submit for JAX review."
Dim originator As Variant
originator = ActiveSheet.Range("B8").Value
If originator = Null Then
Dim originator1 As Variant
originator1 = ActiveSheet.Range("B8").Value
Exit Sub
End If
ActiveWorkbook.SendMail Recipients:=originator, Subject:="Process Approval Request " & ActiveSheet.Range("B12").Value & " - forwarded for next approval"
Application.DisplayAlerts = False
ActiveWorkbook.Close savechanges:=False, routeworkbook:=False
End Sub

Bob Phillips
04-19-2007, 12:57 PM
Why are you using the SendMail dialog before sending it, and what is the point of the originator1 variable?

hibiscus27
04-19-2007, 01:02 PM
Why are you using the SendMail dialog before sending it, and what is the point of the originator1 variable?

I have no idea. I copied that code from someone that didnt know VBA...you can say that the code has been handed down and tweaked by generations.

If there's a better way to do the same thing... please, by all means....let me know!

Thanks.

Bob Phillips
04-19-2007, 01:06 PM
Well, I thinks this would do what you want



Private Sub btnSendNext_Click()
MsgBox "On the next screen, you will see a mail message created with the approval request attached." & Chr(10) & _
"Please address it to the Saltillo Quality Engineer and click the send button."
Dim originator As Variant
originator = ActiveSheet.Range("B8").Value
If originator = "" Then
originator = ActiveSheet.Range("B8").Value
End If
ActiveWorkbook.SendMail Recipients:=originator, _
Subject:="Process Approval Request " & ActiveSheet.Range("B12").Value & " - forwarded for next approval"
Application.DisplayAlerts = False

ActiveWorkbook.Close savechanges:=False, routeworkbook:=False
End Sub

hibiscus27
04-20-2007, 09:29 AM
xld, i used the code that you gave me .... but it sorta worked...but not really.

it did fix the problem of the double email going out, so that's good. :)

...but what it does is that it sends the email automatically to the originator. so basically when the person clicks on the button, they send out an email to themselves instead of allowing them to enter an email address and send manually.

how can i fix this glitch? i would like an email message to open up with the form attached (with whatever that person did saved into the form) and they can address the email to next person for review.

thanks!

feathers212
04-20-2007, 01:14 PM
I use the following format to display an email with the whole sctive workbook attached:

Dim oApp As Object
Dim oMail As Object

'Create and show the outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
'.To =

.Subject = "Process Approval Request " & ActiveSheet.Range("B12").Value & " - forwarded for next approval
.Attachments.Add ActiveWorkbook.FullName
.Display
End With

'Release Outlook
Set oMail = Nothing
Set oApp = Nothing

hibiscus27
04-20-2007, 02:23 PM
Thanks Feathers212 and xld

I used the other code but changed it up a bit after playing around with it...

I deleted a few things and added "" and I got it to work... at least it seems like it does....


'***** Open a new email with project attached to send to next person
Private Sub btnSendNext_Click()
MsgBox "On the next screen, you will see a mail message created with the approval request attached." & Chr(10) & _
"Please address it to the Saltillo Quality Engineer and click the send button."

ActiveWorkbook.SendMail Recipients:="", _
Subject:="Process Approval Request " & ActiveSheet.Range("B12").Value & " - forwarded for next approval"
Application.DisplayAlerts = False

ActiveWorkbook.Close savechanges:=False, routeworkbook:=False
End Sub