PDA

View Full Version : How to define stop in "send" button in custom form?



Wiesiek
05-05-2015, 05:44 PM
Hi,
I`ve been working on custom form for "request meeting" in outlook 2013 lately. As in subject I am not able (with my knowledge) create code in form to define STOP submitting if ,let`s say, textbox1.value <> "YES" ? Maybe it`s totally dumb question but i cannot find anything in web about that kind of problem, maybe i`m asking wrong question? :)

Any known by me commands do not work with "Function Item_Send()" script in form. Do You have any ideas?

Thank You very much in advance for all help!

gmayor
05-05-2015, 11:11 PM
Without seeing your code it is difficult to be precise but on the face of it


If Not UCase(textbox1.Text) = "YES" then Exit Sub

Wiesiek
05-06-2015, 05:15 AM
Hi,
Maybe my question wasn`t clear enough. Only script in custom form VBscript related to "submitt" is function "Function Item_Send()" , after clicking "send" this function is called but "end function" or "end sub" is not working. Form is sent anyway. I found sth like this:


Public WithEvents myOlApp As Outlook.Application

Public Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.Application")
End Sub

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If
End Sub

But i cannot define boolean in VBscript and it`s returning error for code like above. I`m new in custom forms and i don`t know how to create relation to already created code - SEND.

gmayor
05-06-2015, 05:45 AM
If you put the following in the ThisOutlookSession module


Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If
End Sub


It should fire when you click Send on your form and should cancel if cancelled. It certainly does with the preconfigured forms.

Wiesiek
05-06-2015, 06:26 AM
Thank You very much, it works :) Finally i see my mistake, i was trying to implement code inside form code, not Outlook VBA as global sub.
Is there any possibilty to write code as above inside form? I want to distribute it for some users and is there any possibilty to bypass outlook vba and write everything in custom form (VBscript)?