+ Reply to Thread
Results 1 to 18 of 18

inputbox query

Hybrid View

  1. #1
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    inputbox query

    Hello Guys,

    Any ideas why the code below does not work. I am moving emails into different folders of outlook and before that there is an inputbox that pops up. I want to stop the operation when I click cancel or X on the inputbox. Why does not the code below work?

    
    Private Sub oItems_ItemAdd(ByVal Item As Object)
      Static N
      If IsNumeric(N) Then N = N + 1
      N = InputBox("Type ID to be added to the end of the Subject", "Subject ID", N)
      If N = "" Then
      Exit Sub
      Else
      With Item
        .Subject = .Subject & " " & N
        .Save
      End With
      End If
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: inputbox query

    Hi dulitul,

    Try this:

    If (InputBox("Type ID to be added to the end of the Subject", "Subject ID", N)) = vbcanel Then Exit Sub
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    Nope. It does not work. Please help.

    Norie - oh well then I guess I moves the email as I am using an add_item event which is independent from the inputbox. Is it possible to somehow deactivate the event if I click cancel on the inputbox?
    Last edited by dulitul; 08-08-2013 at 07:32 AM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: inputbox query

    The code does stop if you press cancel or click the red cross.
    If posting code please use code tags, see here.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: inputbox query

    When you click cancel the input box the sub is exited, which is going to stop the current event.

    How exactly is the event being triggered?

    What are items being added to?

  6. #6
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    Hello this is the entire code. Whe I drag an email to the folder "controls" an inputbox pops up where I can amend the subject of the email I am dragging. I want the following. If I click cancel on the inputbox I do not want the email to be pasted into the folder. This should be happening only when I type in something in the inputbox.

    Option Explicit
     
    Private WithEvents oItems As Outlook.Items
     
    Private Sub Application_Startup()
      Const MyFolder = "Controls" ' <-- Change to suit
      On Error Resume Next
      With Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
        Set oItems = .Folders(MyFolder).Items
        If Err Then
          .Folders.Add MyFolder
          Set oItems = .Folders(MyFolder).Items
        End If
      End With
      On Error GoTo 0
    End Sub
     
    Private Sub oItems_ItemAdd(ByVal Item As Object)
    
      Static N
      If IsNumeric(N) Then N = N + 1
      N = InputBox("Type ID to be added to the end of the Subject", "Subject ID", N)
    
      With Item
        .Subject = .Subject & " " & N
        .Save
      End With
    
    End Sub

  7. #7
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    Hello this is the entire code. Whe I drag an email to the folder "controls" an inputbox pops up where I can amend the subject of the email I am dragging. I want the following. If I click cancel on the inputbox I do not want the email to be pasted into the folder. The email should be pasted only only when I type in something in the inputbox.

    Option Explicit
     
    Private WithEvents oItems As Outlook.Items
     
    Private Sub Application_Startup()
      Const MyFolder = "Controls" ' <-- Change to suit
      On Error Resume Next
      With Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
        Set oItems = .Folders(MyFolder).Items
        If Err Then
          .Folders.Add MyFolder
          Set oItems = .Folders(MyFolder).Items
        End If
      End With
      On Error GoTo 0
    End Sub
     
    Private Sub oItems_ItemAdd(ByVal Item As Object)
    
      Static N
      If IsNumeric(N) Then N = N + 1
      N = InputBox("Type ID to be added to the end of the Subject", "Subject ID", N)
    
      With Item
        .Subject = .Subject & " " & N
        .Save
      End With
    
    End Sub

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: inputbox query

    You don't seem to have the Exit Sub part in that code.

  9. #9
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    Well. I tried with If (InputBox("Type ID to be added to the end of the Subject", "Subject ID", N)) = vbcancel Then Exit Sub and it does not work.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: inputbox query

    What exactly happens when you try with the orginal code you posted?

    Are you moving more than one item to the folder?

  11. #11
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    Well. The inputbox appears I click on cancel but the email is still pasted into the folder when I drag it. I want to avoid that. When I click on cancel it should stop pasting the email into the folder.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: inputbox query

    When I test the original code it doesn't move the item into the folder if I hit cancel.

  13. #13
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    It certainly is. When you click on cancel the inputbox dissapears and when you go into the folder you can see the email that has been moved. Which code do you use exactly?

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: inputbox query

    So when it didn't move when I tested the code I was seeing things?

  15. #15
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    So what code did you use? When I drag the email into the folder and click cancel on the inputbox the email is still moved..

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: inputbox query

    I used the code you originally posted and this code, which is from post #7.

    Option Explicit
     
    Private WithEvents oItems As Outlook.Items
     
    Private Sub Application_Startup()
      Const MyFolder = "Controls" ' <-- Change to suit
      On Error Resume Next
      With Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
        Set oItems = .Folders(MyFolder).Items
        If Err Then
          .Folders.Add MyFolder
          Set oItems = .Folders(MyFolder).Items
        End If
      End With
      On Error GoTo 0
    End Sub
    I didn't use the rest of the code from that post because the oItems_ItemAdded sub didn't have the Exit Sub the original code had.

    Here's the full code I used.
    Option Explicit
    
    
    Private WithEvents oItems As Outlook.Items
    
    Private Sub Application_Startup()
    Const MyFolder = "Test"    ' <-- Change to suit
    
        On Error Resume Next
        With Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
        
            Set oItems = .Folders(MyFolder).Items
            
            If Err Then
                .Folders.Add MyFolder
                Set oItems = .Folders(MyFolder).Items
            End If
            
        End With
        
        On Error GoTo 0
    End Sub
    
    Private Sub oItems_ItemAdd(ByVal Item As Object)
    Static N
    
        If IsNumeric(N) Then N = N + 1
        
        N = InputBox("Type ID to be added to the end of the Subject", "Subject ID", N)
        
        If N = "" Then Exit Sub
    
        With Item
            .Subject = .Subject & " " & N
            .Save
        End With
    
    End Sub
    PS I changed MyFolder in to 'Test' to suit.

  17. #17
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    All right, norie. Thanks for your help. There is just one more thing. The folder I need the macro for is a shared folder in microsoft exchange server. The code works fine for my personal mail box but not for the shared one. Is there a way to apply it for shared folders?

  18. #18
    Registered User
    Join Date
    12-14-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: inputbox query

    Actually, I want to get the access of a shared sub folder of an email address.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Macro] Excel Query Connection with Inputbox for changing filters
    By JohnGaltnl in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2011, 04:24 AM
  2. InputBox-ow to have a user input text in a inputbox
    By noodle48 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2011, 08:17 AM
  3. Screen positioning inputbox that is set as Application.InputBox
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2010, 07:59 AM
  4. Inputbox button control + msgbox for empty inputbox
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-30-2009, 12:39 PM
  5. InputBox Query
    By Noemi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-04-2006, 06:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1