Linking a Text form field

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Linking a Text form field

Post by ABabeNChrist »

I have 2 text form fields that are used to assit me with google search

Code: Select all

Dim strAddress As String
strAddress = ActiveDocument.FormFields("Street").Result & ", " & ActiveDocument.FormFields("City").Result
strAddress = Replace(strAddress, " ", "+")
ActiveDocument.FollowHyperlink "http://maps.google.com?q=" & strAddress
I use to enter needed address using a userform
I was wondering is it possible to just link data from one part of a doc to a text form field and then run this line of code

User avatar
HansV
Administrator
Posts: 78526
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Linking a Text form field

Post by HansV »

I'm not sure I understand what you're asking. Instead of a to form field, you could refer to a bookmark in the document.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Linking a Text form field

Post by ABabeNChrist »

Thank you Hans
I think I was thinking backward, kind of like the egg before the chicken or is it the chicken before the egg.
Using a bookmark for reference does make much more since as StuartR mentioned in my last post.
The Chicken or the egg.JPG
You do not have the required permissions to view the files attached to this post.

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Linking a Text form field

Post by ABabeNChrist »

Hi Hans
So if I were to use a bookmark for my reference would I then change this line of code from

Code: Select all

strAddress = ActiveDocument.FormFields("Street").Result & ", " & ActiveDocument.FormFields("City").Result
to

Code: Select all

    strAddress = ActiveDocument.Bookmarks("Street").Name & ", " & ActiveDocument.Bookmarks("City").Name

User avatar
HansV
Administrator
Posts: 78526
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Linking a Text form field

Post by HansV »

No, you'd use

strAddress = ActiveDocument.Bookmarks("Street").Range.Text & ", " & ActiveDocument.Bookmarks("City").Range.Text

The expression ActiveDocument.Bookmarks("Street").Name returns the name of the bookmark, i.e. the string "Street".
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Linking a Text form field

Post by ABabeNChrist »

:thankyou: Hans
Works great