Command Button_Click action on Item/Reminder

Sharper1989

New Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
I was hoping for some help, I've got myself confused by cobbling together code found online.


BASIC CONCEPT
  • Email comes into inbox, macro runs off _ItemAdd, mail gets categorized based on some keywords & reminder set for 7 days later (this part working fine!).
  • Then when relevant category reminder fires, original email item from inbox displays AND userform appears over the top with 3 command buttons.
  • (For instance) 1 of these command buttons should run sub-routine ButtonClick_Yes in Module 1 - which creates new email from template, makes original email item an attachment, assign "to" field based on original email & do some changes to email body.

PROBLEM
I'm having trouble working out how to ensure the sub-routine macro has all the relevant references to the original Reminder/ Original mail item.
I don't actually know if I need to use Module1 for the separate sub-routine or if I could run it all through UserForm1 code, but either way the original reminder/email item doesn't seem to be known to either..

Previous advice on VBAExpress was to ensure I listed the items when calling the sub routine from UserForm1, but adding in the full reference Sub ButtonClick_Yes(ByVal Item As Object) gave me a syntax error of: "Compile Error: Expected: List Separator or)" .

So I moved to using ButtonClick_Yes , Item, Object when calling as per below but now I get an error of "Argument Not Optional".



THIS OUTLOOK SESSION
Public WithEvents objInboxItems As Outlook.Items
Public WithEvents OlItems As Outlook.Items

Public Sub Application_Startup()
Set objInboxItems = Application.Session.GetDefaultFolder(olFolderInbox).Items
Set OlItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Public Sub OlItems_ItemAdd(ByVal Item As Object)
Dim obApp As Application
Set obApp = Outlook.Application
If Item.Class = olMail And (LCase(Item.Subject) Like "*invoic*" Or LCase(Item.Body) Like "*invoic*") And Item.Attachments.Count > 0 Then
With Item
.Categories = "Dunning"
.ReminderSet = True
.ReminderTime = Now + 7
.Save
End With
End If
Set obApp = Nothing
End Sub

Public Sub Application_Reminder(ByVal Item As Object)
Dim objFollowUpMail As Outlook.MailItem
If Item.Categories = "Dunning" Then
Item.Display
UserForm1.Show
End If
End Sub

USERFORM1
Public Sub CommandButton1_Click()
ButtonClick_Yes , Item, Object
End Sub

Public Sub CommandButton2_Click()
ButtonClick_No, Item, Object
End Sub

Public Sub CommandButton3_Click()
ButtonClick_Dismiss, Item, Object
End Sub


MODULE1
Public Sub ButtonClick_Yes(ByVal Item As Object)
Dim objFollowUpMail As Outlook.MailItem

Set objFollowUpMail = Application.CreateItemFromTemplate("Example.oft")
With objFollowUpMail
.To = Item.Recipients.Item(1).Address
.Subject = "Follow Up: " & Chr(34) & Item.Subject & Chr(34)
.Attachments.Add Item
.HTMLBody = "Example"
.Display
End With
End Sub



Any help, would be really appreciated! Many thanks.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Item & Object objects need to public variables so they can pass from form to module code.

on the userform code - can you post a screenshot of what the form looks like? Do you actually need a userform or just a message box with yes, no, cancel buttons?

I'm thinking you could do

If Item.Categories = "Dunning" Then
Item.Display

strMsg = "Your question goes here"
intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "whatever goes here")
If intRes = vbYes Then
ButtonClick_Yes Item
End If


' assuming you want to do something beside cancel if no
If intRes = vbNo Then
ButtonClick_No Item
End If


End If

Actually, it might be easier to call a macro that brings up the msgbox. But... depending on what the userform does and looks like you may not need to use it.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This is basically what I would do - if you need to do something if no - then use a second if -

If intRes = vbNo Then
' do whatever
end if


There might be mistakes in the code I added - have not had a chance to test it yet.

Code:
Public Sub Application_Reminder(ByVal Item As Object)
Dim objFollowUpMail As Outlook.MailItem
If Item.Categories = "Dunning" Then

Item.Display

SendReminder Item
End If
End Sub


Public Sub SendReminder(ByVal Item As Object)
Dim objFollowUpMail As Outlook.MailItem

strMsg = "Your question goes here"
intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "whatever goes here")

If intRes = vbYes Then

Set objFollowUpMail = Application.CreateItemFromTemplate("Example.oft")
With objFollowUpMail
.To = Item.Recipients.Item(1).Address
.Subject = "Follow Up: " & Chr(34) & Item.Subject & Chr(34)
.Attachments.Add Item
.HTMLBody = "Example"
.Display
End With

End If

End Sub
 
Similar threads
Thread starter Title Forum Replies Date
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
J Command Button to stamp a date and time in a textbox in Outlook 2016 Outlook VBA and Custom Forms 3
D Command Button code will not execute. Any suggestions Please. Outlook VBA and Custom Forms 2
S Problem running Command button code Outlook VBA and Custom Forms 2
S Code behind form command button Using Outlook 2
M Open new outlook form from within existing outlook form using command button Using Outlook 4
A Command Button Controls Outlook VBA and Custom Forms 6
J Command Button to insert Email Signature Outlook VBA and Custom Forms 2
Z Command button no longer firing after sending custom form over ema Outlook VBA and Custom Forms 1
U Customized Command Button Outlook VBA and Custom Forms 3
J OUTLOOK 2016 FILE STORAGE WHERE COMMAND Using Outlook 12
D Custom Form Accept and Reject Command buttons Outlook VBA and Custom Forms 2
Dr. Demento Outlook version of Excel command? Using Outlook 5
L Outlook Data Files command not working in the quick access bar Using Outlook 1
R Missing Backup command in File menu after installing pfback.exe Using Outlook 2
S Exchange Management Shell closes on command failure Exchange Server Administration 5
P "open" command in right click context menu Outlook Wishlist 4
M "New Appointment from Contact" command missing from Outlook 2003 Using Outlook 1
J Executing Ribbon Command from Code Outlook 2010 Outlook VBA and Custom Forms 3
S How to call a procedure from a custom command bar in Outlook 2007 Outlook VBA and Custom Forms 1
L Outlook 2003 - Set Virables via command line Outlook VBA and Custom Forms 1
T Command bar IDs for Outlook 2007 Using Outlook 2
D Locking Command Bar positions between sessions Outlook Wishlist 0
T Is there a VBA command to Redirect your Emails? Outlook VBA and Custom Forms 1
A How to access command bars in outlook 2007 Outlook VBA and Custom Forms 3
5 How to get Outlook's command line parameters? Outlook VBA and Custom Forms 1
witzker HowTo start a macro with an Button in OL contact form Outlook VBA and Custom Forms 12
R Follow up button doesn't working neither the reminders in BCM BCM (Business Contact Manager) 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
K Disabling import/export button to restrict PST creation Using Outlook 3
N Which Button Was Clicked on the Ribbonbar Menu Outlook VBA and Custom Forms 2
E Can't accept or decline task (no button appears) Using Outlook 2
Q Prompt button to auto turn on Out of Office Outlook VBA and Custom Forms 3
C iCloud Setting missing Outlook tab and Outlook missing the iCloud refresh button Using Outlook 4
witzker Outlook 2010 Insert Date & Time at the button of an OL contactform in red Using Outlook 2
S How to set up button in ribbon for individual Quick Steps Using Outlook 1
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
A ScanPST finding errors but no Repair button Using Outlook 2
N Creating a button or link to a form in the Organizational Forms Library Outlook VBA and Custom Forms 3
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
S Reminder Dialog Open Button Using Outlook 2
Wayne Dardis Calling Ribbon Button in Outlook 2016 Outlook VBA and Custom Forms 6
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
R Categorize Button in Quick Access Toolbar Disappears on New Email Using Outlook 1
E Button to change subject Outlook VBA and Custom Forms 1
S Shortcut/button to a Calendar Group Using Outlook 0
soadfan Enable all rules from toolbar button? Outlook VBA and Custom Forms 3
I Creating meeting invite with disabled tentative button Outlook VBA and Custom Forms 5
Diane Poremsky Contacts are missing when you click the To button New Slipstick.com Articles 0
T Unable to 'Upload a file' using popup 'Browse' button Using Outlook 0

Similar threads

Top