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
Witzker How to get the button Karte ( map) in custom contact form Outlook VBA and Custom Forms 2
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
C Populate form data into message body Outlook VBA and Custom Forms 1
Witzker Outlook 2019 How to get a Photo in a User Defined Contact form Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Set Cursor & Focus from any field to the body of a user Contact form in OL 2019 Outlook VBA and Custom Forms 1
Witzker Place cursor at opening, a user defined OL contact form Outlook VBA and Custom Forms 3
T Customized form: The Forward option shows write layout Outlook VBA and Custom Forms 0
T 1:1 Datatransfer from incoming mail body to customs form body Outlook VBA and Custom Forms 0
V Latest Changes to form not appearing for some users Outlook VBA and Custom Forms 3
J Does the .fdm contain my custom form? How to make ol use it? - ol2007 Outlook VBA and Custom Forms 4
J ol2021 custom form not displaying pics Outlook VBA and Custom Forms 37
bdsermons Outlook 365 command button in outlook form Outlook VBA and Custom Forms 5
wayneame Changing the Form Used by Existing Task Items in a Folder Outlook VBA and Custom Forms 4
N Contact Form Notes Field Touch vs Mouse Using Outlook 0
cbufacchi Outlook 365 Populate custom Outlook Appoint form Outlook VBA and Custom Forms 2
C Create Meeting With Custom Form Outlook VBA and Custom Forms 2
W Designer Form 2013 and Script ? how ? Outlook VBA and Custom Forms 1
J Read Outlook Form fields Outlook VBA and Custom Forms 3
V Compound IF, OR, AND in Outlook form Outlook VBA and Custom Forms 4
J custom form not displaying pictures Outlook VBA and Custom Forms 7
I Button PDF in Outlook Contact custom form Outlook VBA and Custom Forms 1
K Font Sizing in Custom Form Regions for Contacts Outlook VBA and Custom Forms 1
V Validating Outlook form with "OR" and "AND" Outlook VBA and Custom Forms 1
M Outlook 2010 How could I globally redesign an outlook template form/region/inspector template used to display mail lists or an individual mails? Outlook VBA and Custom Forms 0
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

Similar threads

Top