Send email only after previous

Copper Contributor

I would like to send 2 emails to someone.
How would I force the sending of the 2nd email only after the previous has been sent.

I have tried a Yes/No msgbox but the 2nd email still opens in the background, etc.

I want to send the first email and once it's sent only then send the 2nd.

For example (not real code used)

 

Private Sub cmd_email_Click()
Dim strName As String
Dim strMail As String
Dim strTitle1 As String
Dim strTitle2 As String

strName = Me.Firstname
strEmail = Me.email

strTitle1 = "This is the 1st test message"
strTitle2 = "This is the 2nd test message"

DoCmd.SendObject acSendNoObject, "", "", strEmail, , "", strTitle1, "Hi " & strName , True, ""
DoCmd.SendObject acSendNoObject, "", "", strEmail, , "", strTitle2, "Hi " & strName , True, ""
End Sub

 

 


Thank you if you can help.



3 Replies
add a Timer loop between each SendObject.
Example:

'First email
DoCmd.SendObject....
Dim t
t = Timer + .5
Do Until timer > t
DoEvents
Loop
'Second email
DoCmd.SendObject...

Thanks for helping.

If I put a timer on the vba and run the database on a 2 screen system (just so I can see what's happening) the 2 code starts running before the 1st email is sent.

Maybe there is "something like" a popup confirmation I can use once the first mail is sent and outlook closes.

I didn't think this would be a problem - but I have been trying for a while to get this to run.

DoCmd.SendObject acSendNoObject, "", "", strEmail, , "", strTitle1, "Hi " & strName , True, ""
'something here to stop the 2nd DoCmd runing until after the first has completed
DoCmd.SendObject acSendNoObject, "", "", strEmail, , "", strTitle2, "Hi " & strName , True, ""
End Sub

As outlook will close once the first email has been sent I've even tried using this 

 

 

'Run some code here to send the 1st email
Dim myOutlook As Object
On Error Resume Next
Set myOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If myOutlook Is Nothing Then
'some code here to run the 2nd email
End If

 

 


but this still didn't work and the 2nd email starts sending  even if outlook is open (which it shouldn't).

Ha Ha you would think this was simple