Passing a form field as a parameter from Outlook

Status
Not open for further replies.
Outlook version
Outlook 2010 32 bit
Email Account
POP3
I've just spent 6 hours trawling forums and testing some simple (huh!) code that will allow me to open a URL link and include a parameter of a populated field in Outlook.

My page will open as expected, but the parameter gets populated into the field as simple text!!

Reservation Deposit Payment – LewisVille is one example.
Reservation Deposit Payment – LewisVille is another example.

Please help, I'm going nuts.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
BTW, in your example, try
strSubject = objItem.subject
lewisville.uk/payment/?reference=strSubject
 
Outlook version
Outlook 2010 32 bit
Email Account
POP3
BTW, in your example, try
strSubject = objItem.subject
lewisville.uk/payment/?reference=strSubject

Many thanks for your assistance. I used to be an SQL Engineer before surviving 2 strokes 6 years ago. Now my brain struggles!

I have tried each of the following, where the value is a reference that I enter into a field on my User Template.

How do I enter two lines into a hyperlink?
--strSubject = objItem.company
--http://lewisville.uk/payment/?reference=strSubject]

These all open the web page, but value of parameter is NOT passed

--http://lewisville.uk/payment?objItem.company

--http://lewisville.uk/payment?reference = ref(objItem.ItemProperties(company)

Actually redefines the line as
--http://lewisville.uk/payment?reference%20=%20ref(objItem.ItemProperties(company)

--http://lewisville.uk/payment?reference = objItem.company

--http://lewisville.uk/payment?(objItem.company)

How hard can it be to create a one line hyperlink?????
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This sample shows how to pass the subject of the selected message to the url - there are two examples in the code, one using the subject directly, one using a string. If you need just part of the subject, use the string method and left, right, instr, or mid functions.

It's a VBA macro, but could be changed to vbscript to run from a custom form.

Code:
Sub OpenLinksMessage()
Dim olMail As Outlook.MailItem
Dim strURL As String
Dim strSubject As String
Dim oApp As Object
Set oApp = CreateObject("InternetExplorer.Application")

Set olMail = Application.ActiveExplorer().Selection(1)

strURL = "http://lewisville.uk/payment?reference=" & olMail.Subject

strSubject = olMail.Subject
strURL = "http://lewisville.uk/payment?reference=" & strSubject

  
   oApp.navigate strURL, CLng(2048)
   oApp.Visible = True

'wait for page to load before passing the web URL
  Do While oApp.Busy
  DoEvents
  Loop
End Sub
 
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Just to confirm how confused I am. How would I go about adding this to a custom form (template) that I can simply select as a form (template), add a recipient and reference and send. So that the recipient can click on a link and be taken to a web page with the Reference populated from the email?

I might not be explaining it very well, but that just gets me more frustrated as I know I could have done this in the past!!!

Thank you so very much for you time and understanding.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I would probably get the value from the form rather than using it as code behind the form. The fact that it is a custom form only matters if the field you need is a custom field. If you are using default fields, this macro would work with any contact form.


Code:
Sub OpenLinksMessage()
 Dim olContact As Outlook.ContactItem
 Dim strURL As String
 Dim strField As String
 Dim objMsg As MailItem

Set olContact = Application.ActiveExplorer().Selection(1)

'Default fields
 'strField = olContact.Company

' custom fields
 strField = olContact.UserProperties("txtField")

' convert spaces so the url doesn't break
strField = Replace(strField, " ", "%20")

 strURL = "http://lewisville.uk/payment?reference=" & strField

Set objMsg = Application.CreateItem(olMailItem)
 
 With objMsg
  .To = olContact.Email1Address
  .Subject = "This is the subject"
 .Body = strURL
  
  .Display
End With
 
Set objMsg = Nothing
 
 End Sub
 
Outlook version
Outlook 2010 32 bit
Email Account
POP3
You really are being so helpful and patient, thank you.

I have created a Template to fit my needs, is this the same as a form?
How do I go about adding this to my template?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
it is the same as a form. I believe you'll need to publish the template as a form to add code behind it for security reasons. Is the template for new contacts or is it a custom email template? If it's an email template, the macro can load it.
 
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Dear Diane,

The best thing is for me to explain what I am trying to achieve.

I have a website with a hidden page for receiving payments. The intention is to send a customized email (from a template that I have created), containing a reference value. The recipient will be prompted to click on a 'PayPal' icon, which then needs to open the URL of the payment page on the website and populate the Reference field on the form.

I can pass the value as a simple string, using URL ?reference=this value string. However, I thought that I could easily send the value that I enter into the reference value field on the template/email form, as some kind of parameter.

I could do this easily in my SQL scripting days, but cannot find a simple way of passing the contents of reference value field.

Frustratingly yours

Kelvin
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
so the email template that you are sending has the field whose value you need to get? Is it in an Outlook custom field or just entered in the email and you want to grab it from the email and hyperlink it?
 
Outlook version
Outlook 2010 32 bit
Email Account
POP3
I've attached the screenshots of the template that I want to use. Showing properties, etc. You can see from the details, that I am using the field 'Company' to enter the value into and then pass as a parameter. The URL is just one of the seceral URLs that I've tried.
Template a.JPG
Template b.JPG
Template c.JPG
Template a.JPG
Template b.JPG
Template c.JPG
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The problem is that you can't just put the field name in the HTML. You'll need to use a macro to set the value in the underlying url.

This macro worked here - you enter the value then click a button to run the macro and it changes the keyword to the company field value. It is possible to use code behind the form, but so far i can only make it work when i hit save (it's crashing when i try to change it on send)- so you really aren't ahead. And I'm not sure if it will work with a template (.oft) - you might need to use a published form.


I used
Code:
http://lewisville.uk/payment?reference=thecode
as the url in the template.

Code:
Sub ChangeLink()
Dim objMsg As MailItem
Dim strField As String

Set objMsg = Application.ActiveInspector.CurrentItem

  strField = objMsg.UserProperties("Company")
  objMsg.HTMLBody = Replace(objMsg.HTMLBody, "thecode", strField)

  End Sub

to use this, change the url in the template to use thecode where the code belongs. fill out the message then run the macro.
 
Last edited:
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
K TextBox on Custom Form Page :: Passing value from sender to the recipient Outlook VBA and Custom Forms 1
B Passing values from custom form into another form's text box Outlook VBA and Custom Forms 1
N Passing Attachments between forms? Outlook VBA and Custom Forms 2
A How to stop user form from disapearing once mail window is closed? Outlook VBA and Custom Forms 0
K can't get custom form to update multiple contacts using VBA Outlook VBA and Custom Forms 3
V Form data not sending for some users Outlook VBA and Custom Forms 2
H Custom Outlook Contact Form VBA Outlook VBA and Custom Forms 1
witzker HowTo Change message Class of contact form Outlook VBA and Custom Forms 0
A VBscript stops running after updating form Outlook VBA and Custom Forms 1
witzker HowTo start a macro with an Button in OL contact form Outlook VBA and Custom Forms 12
D Emailed form is blank Outlook VBA and Custom Forms 0
F Validation on custom task form after task acceptance Outlook VBA and Custom Forms 1
C Add Form to Appointments Received, Automatically Outlook VBA and Custom Forms 6
V Date and/or time error in Outlook Form Outlook VBA and Custom Forms 0
A Form Position with Dual Monitors Outlook VBA and Custom Forms 2
I Error saving screenshots in a custom form in outlook 2016, outlook 365 - ok in outlook 2013, outlook 2010 Outlook VBA and Custom Forms 5
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
G Other users can't see P.2 with custom fields in Form Outlook VBA and Custom Forms 0
O Create a custom contact form - questions before messing things up... Outlook VBA and Custom Forms 4
L Custom Form Tutoral? Outlook VBA and Custom Forms 6
D Lost Access to Custom Form Outlook VBA and Custom Forms 4
A Form style totally changes Outlook VBA and Custom Forms 2
M vCard does not have user-defined fields from my custom contact form (365) Using Outlook 1
S Outlook Custom Form Scripting only working when clicking on "Run this form" Outlook VBA and Custom Forms 2
V Making a Date field mandatory in outlook form Outlook VBA and Custom Forms 2
R Add 'Company' to Select Names Form Using Outlook 1
Victor_50 Outlook 2013 Custom Contact Form starts with "E-mail 2" Outlook VBA and Custom Forms 2
C Custom Form (seperate layout pages and message reading pane) Outlook VBA and Custom Forms 0
C Reading Pane for Custom Form Outlook VBA and Custom Forms 2
N Custom Form Controls Not Visible To Recipient Outlook VBA and Custom Forms 3
BretAB Is it possible to add a lookup field to a Message form? Outlook VBA and Custom Forms 4
Randy Redekopp How To Merge Contact Info to Email Custom Form Template Using Outlook 2
D Problem with custom form including _DocSiteControl1 Outlook VBA and Custom Forms 0
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
J Program Checkbox that will activate a text box in a Outlook fallible form. Outlook VBA and Custom Forms 1
W Message class changes of a custom form changes to the default form Using Outlook 2
A Possible to hide ribbon with custom appointment form? Outlook VBA and Custom Forms 3
S Custom Form, copy user field data to message body Outlook VBA and Custom Forms 12
Andrew Quirl Custom form to route requests based on input criteria Outlook VBA and Custom Forms 1
Daniel Schunk User-defined form arrives empty at the recipient Using Outlook 3
D Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion Outlook VBA and Custom Forms 4
W Setting up a custom form Outlook VBA and Custom Forms 2
A Greyed out checkbox in custom form Outlook VBA and Custom Forms 4
Z Outlook Custom Form: Adding Dropdown(Project Code) at the end of subject Outlook VBA and Custom Forms 0
Z Adding dropdown list using custom form Outlook VBA and Custom Forms 7
J Approval Form Outlook VBA and Custom Forms 0
G Mass Updating Contact form used Outlook VBA and Custom Forms 8
N Creating a button or link to a form in the Organizational Forms Library Outlook VBA and Custom Forms 3
H VB script in outlook form doesn't work anymore Outlook VBA and Custom Forms 2
J autocomplete function in custom form Using Outlook 1

Similar threads

Top