Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
dthornbery dthornbery is offline
external usenet poster
 
Posts: 1
Default Can one do a find/replace within a drop-down on a form?

We've created a form with a drop-down for names. One of those names has
changed. Can we do a find & replace across the completed forms substituting
the new name for the one that appeared in the drop-down?
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Can one do a find/replace within a drop-down on a form?

Not with find and replace, but you can do it with a macro.

The following will remove an entry from the same dropdown list in a
collection of similar forms placed in a separate folder for that purpose
(test with COPIES!!!). The macro prompts for the folder containing the
documents.

If the old entry is the selected entry in the completed form, then the new
entry will be the selected entry after the macro is run. If the old entry if
not the selected entry, the old entry will simply be removed from the list
and the new entry added.

You will need to change the following lines in the macro to reflect the
information relating to your dropdown field

ddName = "Dropdown1"
The bookmark name of the dropdown field

oldEntry = "Name1"
The entry to be changed *EXACTLY* as it appears in the list

oEPos = 1
The position in the list of the old entry (here the first item in the list)

newEntry = "Name2"
The name you wish to appear as a replacement entry

nEPos = 3
The total number of entries in list. The replacement entry will be added to
the bottom of the list and will be used to check whether the document has
already been processed - so if you run the macro again on the same document,
you won't add the new entry again.

If necessary, see http://www.gmayor.com/installing_macro.htm

Sub ChangeDDEntry()
Dim strFile As String
Dim strPath As String
Dim oDoc As Document
Dim iFld As Integer
Dim oDD As DropDown
Dim ddName As String
Dim oldEntry As String
Dim newEntry As String
Dim oEPos As Integer
Dim nEPos As Integer
Dim fDialog As FileDialog

ddName = "Dropdown1" 'name of dropdown field
oldEntry = "Name1" 'entry to be changed
oEPos = 1 'position in list of old entry
newEntry = "Name2" 'replacement entry
nEPos = 3 'number of entries in list

Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the documents and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) "\" Then strPath = strPath + "\"
End With
WordBasic.DisableAutoMacros 1
If Documents.Count 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFile = Dir$(strPath & "*.do?")
While strFile ""
Set oDoc = Documents.Open(strPath & strFile)
Set oDD = oDoc.FormFields(ddName).DropDown
If oDoc.FormFields(ddName).Result = oldEntry Then
oDoc.FormFields(ddName).Result = newEntry
End If
On Error Resume Next
sNum = oDD.ListEntries(oldEntry).Index
If sNum = oEPos Then 'This is the position in the list of the old entry
oDD.ListEntries(oEPos).Delete
End If
sNum = oDD.ListEntries(newEntry).Index
If sNum nEPos Then 'This is the last entry position
oDD.ListEntries.Add newEntry
End If

oDoc.Close SaveChanges:=wdSaveChanges
strFile = Dir$()
Wend
WordBasic.DisableAutoMacros 0
End Sub

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



dthornbery wrote:
We've created a form with a drop-down for names. One of those names
has changed. Can we do a find & replace across the completed forms
substituting the new name for the one that appeared in the drop-down?



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Protect form but allow find/replace function, spell ck, and add ro Gail B. Microsoft Word Help 2 May 5th 07 05:06 AM
Find multiple characters in one find using MSword find/replace Cliff Microsoft Word Help 2 October 29th 06 07:48 PM
Find/ Replace is auto-capping the words I want to replace with Graham Mayor Microsoft Word Help 8 January 27th 06 01:39 AM
Find and replace in subsequent text form fields? Amanda Boswell Page Layout 1 November 22nd 05 11:00 PM
How do I find & replace "text form fields"? OneClothEar Microsoft Word Help 1 April 13th 05 10:15 PM


All times are GMT +1. The time now is 02:19 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"