Replacing tabs in a formfield text

G

gouved

In my form, I cut and paste into a formfield data that consists of three
strings separated by a tab--"word1 (tab) word2 word3 word4 (tab) word5".
This works fine for one part of my document.

In another part of my document I want the last tab and word5 deleted, and
the remaining tabs replaced with ", " (a comma and a space). Word5 can be
either "self" or "personnel". With an idea from a thread suggesting:

myData=Replace(myData,chr(40),"-"),

I tried setting the formfield value to strVal, replacing the text as follows:

strVal = Replace(strVal, "^tSelf", "")
strVal = Replace(strVal, "^tPersonnel", "")
strVal = Replace(strVal, "^t", ", ")

then saving in another formfield. The resulting text was the same as the
original.

Any suggestions?
 
G

gouved

This is my latest attempt and still not working:

For MedCount = 1 To 7
With ActiveDocument
MedField = "Med" & MedCount
MedBookmark = "S" & MedField
MsgBox (MedBookmark)
OriStrVal = .FormFields(MedField).Result
Selection.GoTo What:=wdGoToBookmark, Name:=MedBookmark
Set BMRange = Selection.range
P_Status = .ProtectionType
If .ProtectionType <> wdNoProtection Then .Unprotect
BMRange.Text = OriStrVal
.Bookmarks.Add MedBookmark, BMRange
' If P_Status > -1 Then .Protect Type:=P_Status, NoReset:=True
'Selection.GoTo What:=wdGoToBookmark, Name:=MedBookmark
End With

'P_Status = ActiveDocument.ProtectionType
'If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t"
.Replacement.Text = ", "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

' If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
Selection.Find.Execute
If P_Status > -1 Then ActiveDocument.Protect Type:=P_Status,
NoReset:=True


Any help appreciated.
 
D

Doug Robbins - Word MVP

Use

Dim str As String
str = ActiveDocument.FormFields("Bmname").result
str = Replace(str, Chr(9) & "self", "")
str = Replace(str, Chr(9) & "personnel", "")
str = Replace(str, Chr(9), ", ")
ActiveDocument.FormFields("Bmname").result = str


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

gouved

Thank you. I found that vbtab also worked. I'll try chr(9). I also found
another thread suggesting Replace$.
 

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