Select message box problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • colinod
    Contributor
    • Nov 2007
    • 347

    Select message box problem

    I have a small code to send emails from a folder within the drafts in outlook 2007

    I am trying to add a yes/no question message before the messages are sent, just incase someone click the button im attaching the code to by mistake.

    VB is not really my thing, i have searched th web and found some codes for the message box but cant seem to intigrate them into this code and have it work

    This is the code

    Code:
     
    Public Sub SendDrafts()
    Dim lDraftItem As Long
    Dim myOutlook As Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myFolders As Outlook.Folders
    Dim myDraftsFolder As Outlook.MAPIFolder
    'Send all items in the "Drafts" folder that have a "To" address filled
    'Setup Outlook
    Set myOutlook = Outlook.Application
    Set myNameSpace = myOutlook.GetNamespace("MAPI")
    Set myFolders = myNameSpace.Folders
    'Set Draft Folder.  This will need modification based on where it's
     
    Set myDraftsFolder = myFolders("Mailbox - Yaketyyak").Folders("Drafts").Folders("statements")
    'Loop through all Draft Items
    For lDraftItem = myDraftsFolder.Items.Count To 1 Step -1
    'Check for "To" address and only send if "To" is filled in.
    If Len(Trim(myDraftsFolder.Items.Item(lDraftItem).To)) > 0 Then
    'Send Item
       myDraftsFolder.Items.Item(lDraftItem).Send
    End If
    Next lDraftItem
    'Clean-up
    Set myDraftsFolder = Nothing
    Set myNameSpace = Nothing
    Set myOutlook = Nothing
    End Sub
    Thsi is some code i have tried to add

    Code:
     
    Dim msg As String
    Dim title As String
    Dim style As MsgBoxStyle
    Dim response As MsgBoxResult
    msg = "Do you want to continue?"   ' Define message.
    style = MsgBoxStyle.DefaultButton2 Or _
       MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
    title = "MsgBox Demonstration"   ' Define title.
    ' Display message.
    response = MsgBox(msg, style, title)
    If response = MsgBoxResult.Yes Then   ' User chose Yes.
       ' Perform some action.
    Else
       ' Perform some other action.
    End If
    i have tried putting this in the send items section of the main code

    can anyone assist me

    thanks
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Code is all right, In MsgBox code,
    ' Perform some action.
    Replace the Above Line With :
    Call SendDrafts

    Regards
    Veena

    Comment

    • colinod
      Contributor
      • Nov 2007
      • 347

      #3
      I get an errror at the
      Code:
      Dim style As MsgBoxStyle
      part of the code

      Comment

      • OuTCasT
        Contributor
        • Jan 2008
        • 374

        #4
        Code:
         
        Select Case MsgBox("Are you sure you want to delete?", MsgBoxStyle.YesNo)
        Case MsgBoxResult.Yes
        --do delete or whatever
        Case MsgBoxResult.No
        - exit and dont delete
        Exit Sub
        End Select

        Comment

        Working...