Home > Net >  Prompt outlook user to enter the value of a userdefined property if not already assigned
Prompt outlook user to enter the value of a userdefined property if not already assigned

Time:03-29

So I'm trying to intercept any new or in reply message and prompt the sender to enter the value for a user defined field if it is not already assigned to the message. The basic flow should be:

user hits send Check if field value is empty IF empty, input box to collect the value and apply Send email as intended.

The user defined field is in place and I'm able to create a form template for sending new emails that allows the sender to input the value before sending. this is intended to act as a verification for new messages and to create the opportunity to apply when replying to previous messages. Any help would be greatly appreciated!

I tried tinkering with other examples of semi-similar functions but to no avail. I'm not a programmer at all so i'm completely lost.

CodePudding user response:

Trap Application.ItemSend event. In the event handler, use the MailItem.UserProperties collection to check if the user property is already present. If not, use InputBox function to show a prompt. Use the returned value to add a user property using MailItem.UserProperties.Add.

CodePudding user response:

The ItemSend event of the Application class is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program. Here is the starting point:

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

But you can use the InputBox function instead of a message box. It displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a string containing the contents of the text box.

Dim Message, Title, Default, MyValue
Message = "Enter a value between 1 and 3"    ' Set prompt.
Title = "InputBox Demo"    ' Set title.
Default = "1"    ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

Finally, the UserProperties.Add method creates a new user property in the UserProperties collection.

Sub AddUserProperty(myItem as MailItem) 
 Dim myUserProperty As Outlook.UserProperty 
 
 Set myUserProperty = myItem.UserProperties.Add("SampleTextUserProperty", olText) 
 myUserProperty.Value = "test"

End Sub
  • Related