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.
 
Is this in an email or a custom form?

You need to set the value of a string to the field value then construct the url. The closest example I have is mapping a meeting location - Map Contact Addresses or Meeting Locations
 
BTW, in your example, try
strSubject = objItem.subject
lewisville.uk/payment/?reference=strSubject
 
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?????
 
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
 
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.
 
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
 
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?
 
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.
 
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
 
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?
 
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
 
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
G Apply Custom Contacts form to all existing Contacts Outlook VBA and Custom Forms 1
G Add Map It button to Custom Contacts Form in Outlook Outlook VBA and Custom Forms 1
G Outlook 2021 Add Picture to Custom Contact Form Outlook VBA and Custom Forms 2
P Can't add custom field to custom Outlook form, it always adds to the Folder instead Outlook VBA and Custom Forms 2
AndyZ Contact Custom Form Tiny Text Outlook VBA and Custom Forms 3
A How to reduce size of custom contact form? Outlook VBA and Custom Forms 3
L Applying new form to existing contacts -- MessageClass Outlook VBA and Custom Forms 3
Geldner Problem submitting SPAM using Outlook VBA Form 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

Similar threads

Back
Top