VBA on again off again 
Author Message
 VBA on again off again

This code worked fine a month ago.  Now it throws up the
error, operation failed, object could not be found, at
the line indicated by the ****'s

Folders haven't been moved, renamed, contaminated, etc.
Outlook 2000 SR-1.

Any ideas?  This code is in a custom toolbar button but
it fails when run directly too.  (Also, is this the usual
way to do this -- all it needs to do is move a message
to a special folder.)

Thanks in advance for any clues.

--

"Life is nothing if you're not obsessed."  --John Waters

Sub MoveToCommentsFolder()
Dim OA As Application, NS As NameSpace, IBX As MAPIFolder
Dim msg As MailItem, PF As MAPIFolder, JM As MAPIFolder
Set OA = CreateObject("Outlook.Application")
Set NS = OA.GetNamespace("MAPI")
Set IBX = NS.GetDefaultFolder(olFolderInbox)
Set PF = IBX.Parent
Set JM = PF.Folders("JMARTIN 1230") ' **** FAILS HERE ****
On Error GoTo QuitIfError
If OA.ActiveWindow.Class = olExplorer Then
    For Each msg In OA.ActiveExplorer.Selection
        msg.Move (JM.Folders("Comments"))
    Next msg
End If
If OA.ActiveWindow.Class = olInspector Then
    OA.ActiveInspector.CurrentItem.Move (JM.Folders("Comments"))
End If
Exit Sub
QuitIfError:
MsgBox "Glitch: " & Err.Description
Set OA = Nothing
Set NS = Nothing
Set IBX = Nothing
Set PF = Nothing
Set msg = Nothing
End Sub



Mon, 14 Nov 2005 07:51:29 GMT  
 VBA on again off again
What error are you getting and if you step through the code is PF a
valid folder?

Did you change any of your project references? Are you sure you are
getting the correct early binding for your Dim's? I always use a full
declaration of any objects to avoid any possible problems (Dim objOL
As Outlook.Application, etc.).

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


Quote:
> This code worked fine a month ago.  Now it throws up the
> error, operation failed, object could not be found, at
> the line indicated by the ****'s

> Folders haven't been moved, renamed, contaminated, etc.
> Outlook 2000 SR-1.

> Any ideas?  This code is in a custom toolbar button but
> it fails when run directly too.  (Also, is this the usual
> way to do this -- all it needs to do is move a message
> to a special folder.)

> Thanks in advance for any clues.

> --

> "Life is nothing if you're not obsessed."  --John Waters

> Sub MoveToCommentsFolder()
> Dim OA As Application, NS As NameSpace, IBX As MAPIFolder
> Dim msg As MailItem, PF As MAPIFolder, JM As MAPIFolder
> Set OA = CreateObject("Outlook.Application")
> Set NS = OA.GetNamespace("MAPI")
> Set IBX = NS.GetDefaultFolder(olFolderInbox)
> Set PF = IBX.Parent
> Set JM = PF.Folders("JMARTIN 1230") ' **** FAILS HERE ****
> On Error GoTo QuitIfError
> If OA.ActiveWindow.Class = olExplorer Then
>     For Each msg In OA.ActiveExplorer.Selection
>         msg.Move (JM.Folders("Comments"))
>     Next msg
> End If
> If OA.ActiveWindow.Class = olInspector Then
>     OA.ActiveInspector.CurrentItem.Move (JM.Folders("Comments"))
> End If
> Exit Sub
> QuitIfError:
> MsgBox "Glitch: " & Err.Description
> Set OA = Nothing
> Set NS = Nothing
> Set IBX = Nothing
> Set PF = Nothing
> Set msg = Nothing
> End Sub



Mon, 14 Nov 2005 21:55:58 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Printer object again and again

2. Again and Again, Bold text in a Listview

3. Turning Identity Off and On Again

4. **** H E L P - Disk Full message (again, and again, and again).....

5. **** H E L P - Disk Full message (again, and again, and again).....

6. VBA remedial again

7. Access to Outlook and back to Access again using VBA

8. SetOption in VBA (again)

9. Pausing VBA code (Again!)

10. HTML view source problem in VBA - Again

11. VBA: Cursors, foiled again!

12. Vba again

 

 
Powered by phpBB® Forum Software