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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close an open email template

Status
Not open for further replies.

Howi

IS-IT--Management
Apr 12, 2001
76
GB
I have some VBA script to open an Outlook email template file, populate 'To' field from the database, open MsgBox requesting Yes or No to send current message.
If YES message is sent, If NO message is not sent and TO field is made blank, ready to be filled from next record.
If the final email is NOT sent, the mail message is left open and needs to be closed manually.

My question is - can I close it from the VBA script?
I know I can close the Outlook application via VBA, but want to leave Outlook open, only close the last mail item that has not been sent.
 
Hi Tony, thanks for the quick reply

pardon my numptyness, but not quite sure what you mean by 'refernce to the inspector'

I use the following code, probably not the best or most elegent, but seems to work.
' start of sending routine
Do Until RS.EOF
If msgTest = "Yes" Then

'open outlook
Set myOLapp = CreateObject("Outlook.Application")
'open email template
Set myitem = myOLapp.CreateItemFromTemplate("C:\test_message.oft")
'put email address from field in TO field
myitem.to = RS("email")
'message box
Msg = "Send email Yes or No?"
Style = vbYesNo
Title = RS("Email")
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
myitem.send
msgTest = "Yes"
Else
myitem.to = ""
msgTest = "No"
End If
RS.MoveNext
Loop

Set myitem = Nothing
End Function



It is the 'myitem' I am trying to close
I can close the 'myOlapp' i.e Outlook but want to leave outlook open.

It is not too important as this only need doing if the last email message is cancelled (Highly unlikely) and can be shut down manually - it's just niggling me that I can'tfind the syntax to do it.
 
myitem.Close 1 '1=olDiscard

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Womderful PHV

All I needed was the 1

Many thanks

Where would we be without this forum???
 
I think you should just be able to do ...

Code:
myitem.Close 1

note that the "1" is the olDiscard constant but you may not have that available if you're using late binding.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top