Converting Form Text Field to Hyperlink

B

beans_21

Hi,

I've got a form and one of the fields is for a web link. Is there anyway
which the web link can automatically be converted in to a hyperlink after its
entered?

Any help would be great :)

Thanks,

Dave
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?YmVhbnNfMjE=?=,
I've got a form and one of the fields is for a web link. Is there anyway
which the web link can automatically be converted in to a hyperlink after its
entered?
It would require a macro. The macro would need to
- unprotect the document
- pick up the information from the form field (hyperlinktext =
doc.Formfields("Name").Result)
- delete the formfield
- insert the hyperlink, using the information you picked up
- reprotect the document without losing user input

You'll find the basic code for unprotecting/reprotecting in the forms section of
my website.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
B

beans_21

Hi,

Thats the kind of thing I'm looking to do, sadly very new to this kind of
thing :(! Where abouts would put the code? Can you name a field? For example
can you set a after update function so when the user moves away from the
particular text box then the hyperlink is automatically put in?

Thanks for the help :)
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?YmVhbnNfMjE=?=,
Thats the kind of thing I'm looking to do, sadly very new to this kind of
thing :(! Where abouts would put the code? Can you name a field? For example
can you set a after update function so when the user moves away from the
particular text box then the hyperlink is automatically put in?
Mmmm, so much depends on the restraints and particulars of the individual
project. Very difficult to give advice. Can you tell us more about how the form
should be used? And which versions of Word are involved?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
B

beans_21

I'm using Word XP, and so will most of the users. The document its self is
to be set up a template for online ordering of books (I work in a college!).
So there are several different fields for example author, title, ISBN number
etc and one of the fields is going to be a link to the where the book is
being ordered from e.g.

http://www.amazon.co.uk/exec/obidos...74340/sr=2-2/ref=sr_2_1_2/202-8387707-0452612

So to make it easy for other people who are going to be using the form (so
very inexperienced users) it would be better if it got changed to a
hyperlink, or if there could be a button (like I saw on your website ;)!)
which they could press and then it would follow the link to the website.

Is it possible to do this?

Thanks for your help :)

Dave
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?YmVhbnNfMjE=?=,
I'm using Word XP, and so will most of the users. The document its self is
to be set up a template for online ordering of books (I work in a college!).
So there are several different fields for example author, title, ISBN number
etc and one of the fields is going to be a link to the where the book is
being ordered from e.g.

http://www.amazon.co.uk/exec/obidos/ASIN/086341463X/qid=1147174340/sr=2-2/ref=sr_2_
1_2/202-8387707-0452612

So to make it easy for other people who are going to be using the form (so
very inexperienced users) it would be better if it got changed to a
hyperlink, or if there could be a button (like I saw on your website ;)!)
which they could press and then it would follow the link to the website.

Is it possible to do this?
It should be, yes. Let me be sure, though, that I understand: the person filling
out the form is giving "you" (the person who will order the books) a hyperlink for
your administrative procedure. So the person filling out the form doesn't need the
tool, just the person who receives the form? In that case, it won't be a problem if
the macro removes the form field and replaces it with a MacroButton field. Here's
some code that does this on my machine OK

Sub ReplaceFormFieldWithHyperlink()
Dim doc As Word.Document
Dim ffld As Word.FormField
Dim rng As Word.Range
Dim sHyperlink As String
Dim fldHyperlink As Word.Field
Dim fldMacroButton As Word.Field

Set doc = ActiveDocument
Set ffld = doc.FormFields("ffHyperlink")
sHyperlink = ffld.Result
Set rng = ffld.Range
If doc.ProtectionType <> wdNoProtection Then
doc.Unprotect
End If
ffld.Delete
Set fldMacroButton = doc.Fields.Add( _
Range:=rng, Type:=wdFieldEmpty, _
Text:="Macrobutton FollowHyperlink XX", _
PreserveFormatting:=False)
Set rng = fldMacroButton.Code
rng.Find.ClearFormatting
rng.Find.Execute FindText:="XX"
Set fldHyperlink = doc.Fields.Add( _
Range:=rng, Type:=wdFieldHyperlink, _
Text:=sHyperlink, PreserveFormatting:=False)
fldHyperlink.Result.Text = "Test"
doc.Protect Type:=wdAllowOnlyFormFields, Noreset:=True
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 
B

beans_21

Hi,

Thats correct a member of staff will fill the form in then a central
administartor will need the hyperlink for the administrative procedure. The
code you gave me looks ace, but when I run the code, I've tried putting it on
to a command button to test it, it always comes stuck on the same bit:

Set ffld = doc.FormFields("ffHyperlink")

Do I need to set the a name for the field that i want to change? Is it
really obvious and I'm being thick?!?!?!

Thank you SO much for your help!

Dave :)
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?YmVhbnNfMjE=?=,
I've tried putting it on
to a command button to test it, it always comes stuck on the same bit:

Set ffld = doc.FormFields("ffHyperlink")

Do I need to set the a name for the field that i want to change?
Yes. In the "quotes" is the name of the field. On my test document, I
named it ffHyperlink. You can use any name you like, as long as you use
the same text in both places. Double-click the form field to open the
Options dialog box. here you can see/change the name.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top