Set Item.SaveSentMessageFolder = objFolder run time error '424'

J

jujoose

when running this macro in outlook run time error '424' occurs. when i
debug, i am taken to the line: Set Item.SaveSentMessageFolder = objFolder is
hilighted as the error. how do i fix this? the purpose of this macro is to
automatically be asked for a folder to store the message in after it is sent.

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
SetItem.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 objInbox As Outlook.MAPIFolder
On Error Resume Next
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
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 objInbox = Nothing
End Function
 
D

Dmitry Streblechenko

MailItem.SaveSentMessageFolder is a set-by-ref property, so you need to use
"set" when setting it.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
J

jujoose

i am really trying, but i dont understand what you mean. i dont see any line
containing MailItem.SaveSentMessageFolder

The line the debug stops on is: SetItem.SaveSentMessageFolder = objFolder

I dont know enough about VBA to know how to change this line. my research
thus far keeps referring to object qualifier, which again i dont know how to
change

can you be a little more detailed on what i should change in the script?
assume i follow directions well!!! i didnt write the script, i got it from:

http://www.outlookcode.com/d/code/setsavefolder.htm

thanks for helping
 
D

Dmitry Streblechenko

Wait a sec. Your code is missing a space:
Change
SetItem.SaveSentMessageFolder = objFolder
to
Set Item.SaveSentMessageFolder = objFolder


Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
J

jujoose

now i get runtime error 438, object does not support this property or method

its like the everready, it just keeps going and going ;)
 
J

jujoose

when i press help at the error, i am given this info, which is french to me,
but may help you???
thanks
Object doesn't support this property or method (Error 438)

Not all objects support all properties and methods. This error has the
following cause and solution:


You specified a method or property that doesn't exist for this Automation
object.
See the object's documentation for more information on the object and check
the spellings of properties and methods.

You specified a Friend procedure to be called late bound.
The name of a Friend procedure must be known at compile time. It can't
appear in a late-bound call.

For additional information, select the item in
 
D

Dmitry Streblechenko

Does that happen when you send any message?
Try to add the following line of code before the offending line:

MsgBox TypeName(Item)

What do you see?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
S

Sue Mosher [MVP-Outlook]

PMJI, but it doesn't look like you're checking for the type of item with the Class property before you display the Pick Folder dialog. Since you can set the SaveSentMessageFolder property only for messages, you need to either check the Class and handle only messages or thrown in an On Error Resume Next statement to ignore the error that other types of items will raise.

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

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

jujoose

after some testing, realize it only errors 438 when sending a calendar item.
from previous help here when sending and email the error 424 has stopped
what you say makes sense in that now it is only the calendar item. i dont
know what line of code to add or change
do you know the code and where to insert it?
--
florida jujoose


Sue Mosher said:
PMJI, but it doesn't look like you're checking for the type of item with the Class property before you display the Pick Folder dialog. Since you can set the SaveSentMessageFolder property only for messages, you need to either check the Class and handle only messages or thrown in an On Error Resume Next statement to ignore the error that other types of items will raise.

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

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

Sue Mosher [MVP-Outlook]

As I indicated, you need to add an If ... Then ... End If block to query the user and set the save folder only if the Class of the item is olMail.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

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

jujoose

thank you for trying to help. i have only used VBA as i put a question out
there for help with assigning a folder automatically in 2007 as it went away
in options in the mail from 2003. i was sent to your link and i loaded the
code and now i can choose the folder when sending the mail.
i do not know how to write this line of code for calendar items you are
telling me about or where to insert it into the original code that was
already there. i understand your logic. i am not versed enough to write it.
thanks for your help
 
S

Sue Mosher [MVP-Outlook]

If you just want to stop the errors, add an On Error Resume Next statement at the beginning of the Application_ItemSend event handler.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

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

Sue Mosher [MVP-Outlook]

I've also posted an updated sample at http://www.outlookcode.com/article.aspx?ID=48 with more bells and whistles. However, you really should not be running code that you don't understand well enough to make simple modifications to. It's just not a safe attitude toward programming code.

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top