View Single Post
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Formatting a Form Field (Telephone Number)

Someone is going to come up with a ridiculously simple approach that works,
but in the meantime you can do it with two macros. The first run on exit
from the telephone number form field (here Text1) and the second run on
entry to the following field. The bulk of the macros is concerned with error
trapping. The macros should allow phone numbers to be entered as 1234567890
or (123)-456-7890 but most other formats should be trapped.

Sub FormatNum()
Dim sPhone As String
Dim sNum As String
sNum = ActiveDocument.FormFields("Text1").Result
If Len(sNum) 10 Then
If Len(sNum) 10 Then
If Len(sNum) 14 And InStr(1, sNum, "(") 1 Then
MsgBox "Incorrect telephone number format." & vbCr & _
"Insert 10 digits without spaces" & vbCr & _
"For (123)-456-7890 enter 1234567890", vbCritical, _
"Number entry error"
Exit Sub
End If
End If
End If
sPhone = Format(sNum, "(000)-000-0000")
ActiveDocument.FormFields("Text1").Result = sPhone
End Sub

Sub FormatError()
Dim sNum As String
sNum = ActiveDocument.FormFields("Text1").Result
If Len(sNum) 10 Then
If Len(sNum) 14 And InStr(1, sNum, "(") 1 Then
ActiveDocument.FormFields("Text1").Select
End If
End If

http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP

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



Suzanne S. Barnhill wrote:
I can't get this to work with parentheses, which apparently can't be
included in a "number format," but if you set the form field type to
"Number," set 12 as the maximum number of characters, and then use
000-000-0000 as the number format (checking the box for "Calculate on
exit"), users can enter numbers continuously, and when they tab out
of the field the result will be formatted as 123-456-7890. I can't
help feeling there must be some way to accomplish this with the
format you want, but I haven't been able to achieve it. It would
appear not to be possible to add formatting switches to FORMTEXT
fields, so that's no help, either.

"Lilbit" wrote in message
lkaboutsoftware.com...
Is it possible that when a user lands on a form field, that form
field will
show ( )___-____. When they go to type in the telepone number,
the 1st digit will appear after the open parenthesis; after typing
in the third digit, it will jump to the 1st underlined space; after
typing in three numbers, it will jump to the 1st underlined space
after the dash so they can type in the last four numbers? Thanks!!

--
Message posted using
http://www.talkaboutsoftware.com/gro...docmanagement/
More information at http://www.talkaboutsoftware.com/faq.html