Email Item Move causes Object Required error - very short program

J

Joe

Hi. This seems pretty basic, but I've been racking my brains.
I'm using VBA in Outlook 2003.
I want to move an email from the Inbox folder to a sub-folder.
I get Run-time error '424' - Object Required when the Move method is
executed on the email.
The email and folders exist and are the ones I want at the time of the Move.
I see them in the Locals window.
It does make it to the Move, so the objects look right to me.
Thanks for you help.
Here's the code:

Sub MoveEmail()
Dim fdrInbox As Outlook.MAPIFolder
Dim fdrDone As Outlook.MAPIFolder
Dim itmEmail As Outlook.MailItem

Set fdrInbox =
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set fdrDone = fdrInbox.Folders.Item("Done")
Set itmEmail = fdrInbox.Items.Item(1)

If TypeName(itmEmail) = "MailItem" Then
If TypeName(fdrDone) = "MAPIFolder" Then
itmEmail.Move (fdrDone)
End If
End If
End Sub
 
J

Josh Einstein

My VB6 is *very* rusty, but have you tried removing the parenthases from
(fdrDone) in the itmEmail.Move method? Sorry it's just a stab.
 
J

Joe

Thanks Josh. That did it. I guess your VB6 is still doing ok. Mine on the
other hand....

So I guess it came down to: Sub calls (without using the Call keyword) take
their arguments without parenthesis. Function calls take their arguments in
parenthesis. The tooltip that pops up threw me off. It showed the
parenthesis.

I wonder why it gave the Object Required error though. Any thoughts?

-Joe
 
J

Josh Einstein

Well from what I recall, putting parenthases around a sub call (which by the
way only succeeds if you have one parameter) copies the value of the
expression (the object reference) and passes that. But I'm not sure why that
causes a problem in VB but I recognized the Sub call and figured I'd suggest
it. Glad it worked.
 

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