Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook - Go to Next item after delete

Status
Not open for further replies.

rocksandbroncs

Technical User
Jan 8, 2001
19
0
0
US
Please bear with me as I know virtually nothing about VBA.

The object is to have a button on each of the item forms that will permanently delete an item - not just move it to the deleted items folder - and then go to the next item.

Thanks to this thread I was able to get the permanently delete part working but as soon as the item is deleted, the form window is closed. I want this button to emulate the normal delete button i.e. perform the delete action - and then go to the next item, if available. I'm mostly concerned in having this work for mail items. Any problems with other type items I can adjust as needed.

So far I've got:

Code:
Sub PermDelItem()
  
    Dim oApp As New Outlook.Application
    Dim oThisItem As Object
    Dim oMyNameSpace As NameSpace
    Dim oDelItemsFldr As MAPIFolder
    Dim oCurrItemFldr As MAPIFolder
    Dim oDeletedItems As Object
    Dim intItemCount As Integer
    
    Set oMyNameSpace = Outlook.GetNamespace("MAPI")
    Set oThisItem = oApp.ActiveInspector.CurrentItem
    
    
    Set oCurrItemFldr = oApp.ActiveExplorer.CurrentFolder
    ' Set ItemsList = oCurrItemFldr.Items.Item(.Subject = oThisItem)
    
    ' Prompt for confirmation
    strPrompt = "Are you sure you want to permanently delete this item?"
    If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
        oCurrItemFldr.Items.GetNext
        oThisItem.Delete
        Set oDelItemsFldr = oMyNameSpace.GetDefaultFolder(olFolderDeletedItems)
        Set oDeletedItems = oDelItemsFldr.Items
        intItemCount = oDelItemsFldr.Items.Count
        oDeletedItems.Item(intItemCount).Delete
    End If


End Sub

The GetNext method doesn't work and I can't figure out why. As I said earlier, I'm in way over my head here, but willing to learn. Wish Outlook had the ability to create a macro via recording, like the other apps do. That would get me a lot closer a lot faster :-D.

TIA for any help.

WARNING! New virus! [wink] PBS VIRUS - Your computer stops every few minutes to ask for a tax deductible contribution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top