PC Review


Reply
Thread Tools Rate Thread

Can one do a find/replace within a drop-down on a form?

 
 
dthornbery
Guest
Posts: n/a
 
      27th Jan 2009
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 With Quote
 
 
 
 
Graham Mayor
Guest
Posts: n/a
 
      28th Jan 2009
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace form =?Utf-8?B?YWNfZXZv?= Microsoft Frontpage 3 3rd Nov 2005 01:58 AM
Find Replace in a Form =?Utf-8?B?Y2FybA==?= Microsoft Outlook Discussion 0 2nd Mar 2005 07:41 PM
find and replace in form =?Utf-8?B?QW5kcmVqIEZlbmlr?= Microsoft Access Forms 0 19th Nov 2004 02:59 PM
Cleaing The Find and Replace Drop Down Fuse - News Microsoft Frontpage 2 2nd May 2004 04:04 AM
Use of Find Replace when form open Rick Microsoft Access Forms 0 9th Mar 2004 12:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:58 PM.