Converting Word Forms to CSV

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

So I've created a Word form for the purpose of uploading to a database. I
overlooked the fact that when a user presses enter within a field, it results
in a line break in the txt file. Is there a way to avoid this and have Word
ignore the carriage return within fields?

Thanks
 
Lonergan:

I don't know of any simple option you can set to disallow entry of paragraph
(CrLf) marks in a text box.

I think you'll need to create an On Exit macro that replaces CrLf in the
entered text with a space or with a placeholder symbol.

Bear
 
One solution would be a variation on the validation macro at
http://www.gmayor.com/formfieldmacros.htm
For full details read the web page, but this version adds a line to the
AonExit macro to change 'enter' to a space. The macros also force completion
of the fields.

Private mstrFF As String

Public Sub AOnExit()
With GetCurrentFF
If Len(.Result) = 0 Then
MsgBox "You can't leave field: " & .Name & " blank"
mstrFF = GetCurrentFF.Name
End If
.Result = replace(.Result, Chr(13), " ")
End With
End Sub

Public Sub AOnEntry()
Dim strCurrentFF As String

' Goto another FormField if we weren't supposed to leave it!
If LenB(mstrFF) > 0 Then
ActiveDocument.FormFields(mstrFF).Select
mstrFF = vbNullString
End If
End Sub

Private Function GetCurrentFF() As Word.FormField
Dim rngFF As Word.Range
Dim fldFF As Word.FormField

Set rngFF = Selection.Range
rngFF.Expand wdParagraph

For Each fldFF In rngFF.FormFields
Set GetCurrentFF = fldFF
Exit For
Next
End Function


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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

Back
Top