Preventing the Send button from being clicked on an Outlook Form

Not open for further replies.


New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I have many Outlook forms that I have "inherited" and most use code to check the form has been completed properly, then construct an email based on the contents of the form. The reason for this is to ensure that the email sent as a result of submitting the form is in a standard format that can then be "read" by various automation tools. It's a clanky approach I know, but I can't change things (politics).

So the method used when we were using 2003 doesn't appear to work in 2010... and this is how most have been written:
Sub Item_Send()

    If SendFlag = 1 Then
        MsgBox "Please use the Submit button at the bottom of this page"
      exit sub
    End If
End Sub

Then the code behind the Submit button as follows:
Sub cmdSubmit_Click()

    Set csprps = Item.UserProperties
    Set csitm = Item.GetInspector
    Set cspgs = csitm.ModifiedFormPages
    Set cspg = cspgs("Form")
    Set csctls = cspg.Controls

    'Set Send Flag
    SendFlag = 1
     ' Loads of code to validate the field data etc.

'Build message body
       varSubject = "New Request"
       varReceipient = "relevant mailbox"
       varMessageBody = "Please process the following request" & vbCrLf & vbCrLf & _
          "001 Name: " & csprps("A001") & vbCrLf
        'loads more code to build the message body

    'Build up and send the message
    Set objOutlook = CreateObject("Outlook.application")
    Set mItem = objOutlook.CreateItem(olMailItem)
    mItem.To = varReceipient
    mItem.Subject = varSubject
    mItem.Body = varMessageBody
    SendFlag = 2

    ' ****  Clean up
    Set mItem = Nothing
    Set objOutlook = Nothing
    ' Close item without saving
    Item.Close (1)

End Sub

The issue is that the Item_Send code runs (when either Send or Submit is clicked) but doesn't prevent the form from being sent when the user has clicked Send rather than Submit. It does show the message box when Send is clicked and not when Submit is clicked, but the exit Sub doesn't stop it from being sent.
It then arrives as a form rather than the formatted text that the code behind the submit button would send.

Is there a way I can cancel the "Send" either easily or more elegantly?

Many thanks in anticipation!
At a first glance I don't understand why it has worked at all, so maybe I'm missing anything. It's VB Script, not VBA, isn't it?

I'm not familar with VBS, but Item_Send is a function, not a sub (at least in OL 07, and I don't think it's been changed). The difference is that a function returns a value. I guess, you need to return False if you want to cancel the sending process, or return True if you want to proceed.

As Item_Send is being called when a message is going to be sent, I don't get why Item.Send is called (again) within that procedure.
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
H Preventing the 'email address fetch from Exchange' crashing email reading code Exchange Server Administration 0
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
G Bcc help - Preventing multiple forwards from a bcc'd distribution group Using Outlook 1
D Preventing users to disable an Outlook Add-in Using accounts in Outlook 5
M Preventing conversation from moving to the top of the message box? Using Outlook 7
R How to use VB .Net to send emails? Outlook VBA and Custom Forms 0
J Outlook VBA to send from Non-default Account & Data Files Outlook VBA and Custom Forms 3
C Synchronization and taking forever to send Using Outlook 2
D Send on behalf of does not store the base mailbox Using Outlook 0
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0
S Outlook 2002- "Send" button has disappeared. Help please. Using Outlook 1
TomHuckstep Remove Send/Receive All Folders (IMAP/POP) button from Outlook 365 Ribbon Using Outlook 2
J Macro to send email as alias Outlook VBA and Custom Forms 0
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
T Outlook 2010 recipient no longer shows in 'Send To' Using Outlook 0
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Geldner Tweak Junk Email Reporting tool to default to particular email on send? Using Outlook 3
Geldner Send / Receive a particular group via macro or single keypress Using Outlook 1
E Outlook - Macro - send list of Tasks which are not finished Outlook VBA and Custom Forms 3
L How to avoid issues with "Send on Behalf" Using Outlook 3
M Outlook 365 refuses to send email Using Outlook 0
A Change settings Send/receive VBA Outlook VBA and Custom Forms 0
M I cant send emails via Outlook in my W10 PC. Using Outlook 3
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
G Send a greeting message to a contact on birthday Outlook VBA and Custom Forms 5
T Outlook creates a copie of every mail I send Using accounts in Outlook 4
R How to restrict GWSMO sync to Outlook Send/Receive cycles Using Outlook 0
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
A Unflag Inbox and Flag Inbox with Orange Category After Item is send Outlook VBA and Custom Forms 3
glnz O365 - How to send from acct 2 but showing email name from acct 1 as From - alias? Using Outlook 0
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
C Synchronizing subscribed folders causes hanging during send/receive process Using Outlook 2
M Extract all links from Outlook email, send to Excel Using Outlook 2
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
O Outlook 365 - suddenly unable to send using Gmail POP3 Using Outlook 10
T After I send a new email, it remains in the Draft folder Using accounts in Outlook 3
B Programmatically force html send and insert clipboard contents into body Outlook VBA and Custom Forms 0
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
M ERROR: None of your email accounts could send to this recipient Using Outlook 2
C Send/receive error 80040119 Using Outlook 2
J Send Again NDR Outlook VBA and Custom Forms 1
J Add an Attachment Using an Array and Match first 17 Letters to Matching Template .oft to Send eMail Outlook VBA and Custom Forms 2
ChrisK2 Send email to fails: "The group advertising isn't set up to receive messages from..." Using Outlook 3
B resend if no reply and send an automatic reminder Outlook VBA and Custom Forms 0
F Send As a Gmail account via outlook Web Using Outlook 3
R auto send email when meeting closes from a shared calendar only Outlook VBA and Custom Forms 2
X Unable to send an email from one account to another on same PC Using Outlook 2

Similar threads