autotextlist form field

G

Guest

I am making a template using text form fields, drop down
list fields, check boxes, fill-in fields, and autotextlist
fields. I lock the form and all the fields are available
to fill in, etc. EXCEPT the autotextlist field. I can
only be used, it seems, when the template is not locked.
Since most of the people that will be using this form are
not that computer literate, I don't want them locking the
form for some fields and unlocking the form for other
fields. I would like to lock my template and be able to
have all fields accessable. Can anyone out there help???

Thanks
 
P

Peter Jamieson

As far as I know the only way you could do this would be to insert a
continuous section break, put the regular forms fields in one section of the
document and protect it, and put your autotextlist field in the other
section and leave it unprotected. But that may not suit your format, and I
think users would find the experience awkward unless you already have an
unprotected section in your document.

Could you get away with a drop-down list? (perhaps populated by a macro from
the appropriate autotexts?)
 
P

Peter Jamieson

Could you get away with a drop-down list? (perhaps
populated by a macro from

Thinking about it some more I've probably misunderstood what you want, as
you say you are already using Drop Down List boxes, and my suggestion can
only be made to work if the texts to be selected are just plain text, not
autotexts with formatting or graphics. But I may as well say what I had in
mind anyway.

Suppose you insert a drop down list from the Form toolbar. Eventually we'll
call the list box ddATL.

Then step 1 might be to
a. create a VBA subroutine called ddATL_Populate, and use it to populate
the Drop Down List with the texts the user can select:

Sub ddATL_Populate()
Const ddATL="ddATL"
With ActiveDocument.FormFields(ddATL).DropDown.ListEntries
.Clear
.Add Name:="Item 1 in the list"
.Add Name:="Item 2 in the list"
' etc...
End With
End Sub

Then select the dropdown list and edit its properties, setting its name to
ddATL. You can either populate the list as a one-off action (just run the
subroutine, protect the form, save the document), or populate it each time
you open the document, e.g. by calling ddATL_Populate from an AutoOpen
macro, or you can populate it each time the user tabs into the list by
setting the "Run macro on entry" property to ddATL_Populate.

So far, all this will let you do is let the user select from the fixed texts
"Item 1 in the list" etc. Instead, you could populate the drop down with the
contents of the Autotexts using a macro such as the following. In this case
you would probably need to populate the drop-down when you open the document
since you are probably trying to pick up whatever autotexts are contained in
the attached template.

Sub ddATL_Populate()
Const ddATL="ddATL"
Dim oAutoTextEntry As AutoTextEntry
With ActiveDocument.FormFields(ddATL).DropDown.ListEntries
.Clear
' Here, we just use the autotexts in the Attached template...
For Each oAutoTextEntry In ActiveDocument.AttachedTemplate.AutoTextEntries
' ...associated with the style "Normal"
If oAutoTextEntry.StyleName = "Normal" Then
' This check is essential - others may be needed
If oAutoTextEntry.Value <> "" Then
.Add Name:=oAutoTextEntry.Value
End If
End If
Next
End With
End Sub

If what you really want to do is let the user select the /name/ of an
autotext here, but insert the associated text elsewhere in the document,
then you could
a. change the above routine to use the autotext name rather than the value:

Sub ddATL_Populate()
Const ddATL="ddATL"
Dim oAutoTextEntry As AutoTextEntry
With ActiveDocument.FormFields(ddATL).DropDown.ListEntries
.Clear
' Here, we just use the autotexts in the Attached template...
For Each oAutoTextEntry In ActiveDocument.AttachedTemplate.AutoTextEntries
' ...associated with the style "Normal"
If oAutoTextEntry.StyleName = "Normal" Then
' This check is essential - others may be needed
If oAutoTextEntry.Name <> "" Then
.Add Name:=oAutoTextEntry.Name
End If
End If
Next
End With
End Sub

b. insert a bookmark named txtATL at the point where you want the result
text. Make sure it is not a "point" bookmark, i.e. it should "mark" at least
one character, such as a space.
c. create another Sub called ddATL_Exit
d. modify the properties of the drop down list so that the "Run macro on
Exit" property is set to ddATL_Exit

Put the following in ddATL_Exit

Sub ddATL_Exit()
Const bkmATL = "bkmATL"
Const ddATL = "ddATL"
Dim lListEntry As Long
Dim sAutoTextName As String
Dim oAutoTextEntry As AutoTextEntry
Dim oBookmark As Bookmark
Dim oRange As Range
'Re-insert the bookmark
With ActiveDocument
Set oRange = .Bookmarks(bkmATL).Range
lListEntry = .FormFields(ddATL).DropDown.Value
sAutoTextName = .FormFields(ddATL).DropDown.ListEntries(lListEntry).Name
.AttachedTemplate.AutoTextEntries(sAutoTextName).Insert where:=oRange,
RichText:=True
.Bookmarks.Add Name:=bkmATL, Range:=oRange
End With
End Sub

However, the user will need to press tab or otherwise exit the drop down
field for the bookmark's content to be updated. Also, there may be a problem
with this code if one of the autotexts is empty.

Let us know if I've completely missed the point, and what exactly it is that
you want to do.
 

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