Dorpdownlist as result of a value of a bookmark

E

Evert

Hi all,

I am totaly new at this scripting and searched many of your already problems
but could not find a solution for my question so here it is....

In my form (Word 2003) I have a bookmark with a certain value (which is
determined by a dropdown box choosen value). This bookmark has a value TEL04A
or TEL04B. When the value is TEL04B then I would like to have a dropdown box
created and visible to the filler of the form but if it is TEL04A the box may
not be shown at all.

I tried this with the scripting below which does not give any error but also
does not give me a dropdown box.

So.... the question here is: what is wrong with the scripting or what am I
not doing correctly?

Thx

Evert


Sub optipointselekt()
If ActiveDocument.Bookmarks("tel04") = "TEL04B" Then
ActiveDocument.Bookmarks("stdadv").Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormDropDown
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "soortoptipoint"
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
End With
Selection.FormFields("soortoptipoint").DropDown.ListEntries.Clear
Selection.FormFields("soortoptipoint").DropDown.ListEntries.Add Name:= _
"Standard"
Selection.FormFields("soortoptipoint").DropDown.ListEntries.Add Name:= _
"Advanced"
End If
End Sub
 
G

Greg Maxey

Evert,

You will need a plain bookmark stdadv where you want the field to
appear. As you can never tell what your users will do, it is a bit
more complicated than just having the result of the first dropdown add
a new field. What if the user changes their mind and then changes it
again ;-)

Try this on exit from the dropdown named "tel04":

Sub optipointselekt()
Dim oFfld As FormFields
Dim oRng As Word.Range
Dim oDoc As Word.Document
Set oDoc = ActiveDocument
Set oFfld = oDoc.FormFields
Set oRng = oDoc.Bookmarks("stdadv").Range
oDoc.Unprotect
If oFfld("tel04").Result = "Tel04B" Then
If Not ActiveDocument.Bookmarks.Exists("soortoptipoint") = True Then
oFfld.Add Range:=oRng, Type:=wdFieldFormDropDown
With oRng.FormFields(1)
.Name = "soortoptipoint"
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
End With
With oFfld("soortoptipoint").DropDown.ListEntries
.Clear
.Add "Standard"
.Add "Advanced"
End With
oFfld("soortoptipoint").DropDown.Value = 1
End If
Else
If ActiveDocument.Bookmarks.Exists("soortoptipoint") = True Then
oFfld("soortoptipoint").Delete
End If
End If
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub

I didn't extensively test, but if the second formfield already exists
then you either want to ignore adding it again or delete it if
depending on subsequent user actions.
 
E

Evert

I now get an error requested member of the collection does not exists. I will
send you an email about it. Hope you don't mind that.....
 

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