Working macro now fails.. why?

D

Dan

Hi there,

i have a very simple macro partially from Sue Mosher's book. The purpose of
it is to set a customized reminder on a selected mailitem. I have a button
on the toolbar firing this macro (MySetReminder()). This worked fine for
more than a week. But now it suddenly creates a VBA error: Run-time error
'-2147221241 (80040107)': Method 'FlagDueBy' of 'MailItem'failed.

The script is below. i can't recall having changed anyhing. And now i am
puzzled why it suddenly stopped working.. Any pointers are very much
appreciated.

Thanks

Daniel

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application

Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select

Set objApp = Nothing
End Function

Sub MySetReminder()
Set objItem = GetCurrentItem()
With objItem
.FlagDueBy = Date + 10 ' here it
fails !!!
.FlagRequest = "Check what has happened"
.FlagIcon = 4
.FlagStatus = olFlagMarked
.Save
End With
End Sub
 
G

Guest

Check the MessageClass and/or Class properties of the object returned by
GetCurrentItem; only MailItem and MeetingItem objects support the FlagDueBy
property, and setting this will fail for other types of items.

The only other things I can suggest is to handle cases where nothing is
selected in the Explorer in GetCurrentItem, and to check for instances where
objItem Is Nothing in MySetReminder.
 
D

Dan

Thanks Eric,

Checked with a Watch. The returned item is of type Variant/Object/MailItem.
Must be obvious since I select only in the Mail view.
What is strange is that the Watch window will show me <No Variables> when I
open objItem in there... i am not sure, but I believe I should see the
object structure in there??

Strangely, the macro worked exactly in this configuration for the last
couple of days. And I was really using it. Just since today I does not want
to do anything anymore...

Dan
 
D

Dan

Some more
The MySetReminder() actually works in the following folders:
- Sent Item Folders
- Any local PST folder

It does NOT work (with the error I described earlier) in the following
Folders
- Inbox
- Any Search Folders (I am running Outlook 2003) --> AHA!!!

Well.. this remembered me that I sometimes have my problems with Search
Folders. I am using them very extensively. And sometimes I come into a
situation when Search Folders are not accessible anymore. That is it would
disply a grey window with the text inside "Can't Display Folder". The only
solution to fix this is to restart Outlook..

Said, done... The result... my macro works again!!

Conclusion: There is a Search Folder Bug in Outlook 2003 that has some
impact on macro programming, especially when selecting an item out of a
Search Folder..

Just wanted to share this conclusion with you

Dan
 
G

Guest

I wouldn't describe your problems with Search folders as having an impact on
macros. If the Search folder is corrupt for any reason or cannot be
displayed, any macros depending on returning an object from a selection in
that folder should handle these circumstances.

I've had no problems setting flag info on open items or selected items in a
current Search folder.

FYI, there is a known issue with Search folders:

You receive an “Unable to Display Folder†error message when a search
includes a deleted folder in Outlook 2003:
http://support.microsoft.com/default.aspx?scid=kb;en-us;820717

See also:

How to troubleshoot Search Folders in Outlook 2003:
http://support.microsoft.com/default.aspx?scid=kb;en-us;831402
 
D

Dan

Hi Eric,

Yeah, I was probably not accurate with my wording.

My macro DOES work in Search Folders. However, sometimes Search Folders seem
to have problems (as mentioned in your links, but by the way, I am using
Exchange 2000 and thus the error description does not match). If Search
Folders have "problems" on my PC, it apparently shows as "Unable to Display
Folder" OR my macro stops working.

The fix for both is to restart Outlook. After that, the macro works again in
the same Search Folder.

So, I do not have a corrupt Search Folder.. Just my Outlook 2003 has some
problems with Search Folders from time to time :)

I can live with that.. only happens once or twice a week.

Thanks for your support!!

Dan
 

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