<Sue Mosher> VB Code Modification

  • Thread starter Thread starter Ray Batig
  • Start date Start date
R

Ray Batig

Sue,

Your code to provide the Lotus Notes like Send and File is working great. I
would like to change the default folder from the Inbox folder to the
Deleted Items folder. In that way, I can click OK to send and not save a
copy, click cancel to send it to the Sent folder, or select the desired
folder and click OK. I have proposed the changes below. Since I am a newbee
to VB in Outlook, I figured it was better to ask before trying.....

Thanks in advance for your help!

Ray

Private Sub Application_ItemSend(ByVal Item As Object, _
Cancel As Boolean)
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" And _
IsInDefaultStore(objFolder) Then
Set Item.SaveSentMessageFolder = objFolder
End If
Set objFolder = Nothing
Set objNS = Nothing
End Sub

Public Function IsInDefaultStore(objOL As Object) As Boolean
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objDeleted Items As Outlook.MAPIFolder Replaces Dim objInbox As
Outlook.MAPIFolder
On Error Resume Next
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objDeleted Items = objNS.GetDefaultFolder(olFolderDeleted Items)
Replaces Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Select Case objOL.Class
Case olFolder
If objOL.StoreID = objInbox.StoreID Then
IsInDefaultStore = True
End If
Case olAppointment, olContact, olDistributionList, _
olJournal, olMail, olNote, olPost, olTask
If objOL.Parent.StoreID = objInbox.StoreID Then
IsInDefaultStore = True
End If
Case Else
MsgBox "This function isn't designed to work " & _
"with " & TypeName(objOL) & _
" items and will return False.", _
, "IsInDefaultStore"
End Select
Set objApp = Nothing
Set objNS = Nothing
Set objDeleted Items = Nothing Replaces Set objInbox = Nothing
End Function
 
You're referring to the sample at http://www.outlookcode.com/d/code/setsavefolder.htm? There is no default folder in that code. The Inbox folder is used in the IsInDefaultStore() function merely to determine if the folder the user chose is in the default information store.

So, here's the problem with your scenario: The PickFolder method has only two outcomes. Either it returns Nothing (when you don't choose a folder) or it returns the folder you chose. There's no way to get 3 outcomes from it. If you want to support a third outcome, you'll need to use some other mechanism -- the simplest being a MsgBox prompt -- to ask the user what to do. That's the point at which, it seems to me, things are getting too complicated. Answering one prompt on sending seems OK. Answering two seems intrusive. And designing a VBA userform with a checkbox (save it? Yes/No) and a tree control filled with the Outlook folder hierarchy might be more VBA programming than you want to take on for this purpose.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Hi Sue,

You are correct in the reference. It appeared to me that the In box folder
was a default since when you run the vb code by clicking Send, the In Box
folder is highlighted in the selection pop up. If you simply click OK, the
message is filed in the In box folder. If you click cancel, the message is
filed in the Sent folder. All I was then deducing that I would like is to
have the pop up folder list by default highlight Deleted Items so if I
clicked OK the message would go to the Deleted Items folder ( I don't want
to save a copy. ) or if I clicked cancel the message would go to the Sent
folder like it currently does, or lastly, if I selected any other folder and
clicked OK the message would be saved there.

So by deduction, somehow the vb code picks the In box.....


I hope this is no too confusing. I agree that you don't want to complicate
the process with two pop ups. I have ordered your book, hopefully it will
help me learn.

Thanks

Ray

You're referring to the sample at
http://www.outlookcode.com/d/code/setsavefolder.htm? There is no default
folder in that code. The Inbox folder is used in the IsInDefaultStore()
function merely to determine if the folder the user chose is in the default
information store.

So, here's the problem with your scenario: The PickFolder method has only
two outcomes. Either it returns Nothing (when you don't choose a folder) or
it returns the folder you chose. There's no way to get 3 outcomes from it.
If you want to support a third outcome, you'll need to use some other
mechanism -- the simplest being a MsgBox prompt -- to ask the user what to
do. That's the point at which, it seems to me, things are getting too
complicated. Answering one prompt on sending seems OK. Answering two seems
intrusive. And designing a VBA userform with a checkbox (save it? Yes/No)
and a tree control filled with the Outlook folder hierarchy might be more
VBA programming than you want to take on for this purpose.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Unfortunately, Outlook provides no way to set the default folder used by the PickFolder method.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top