Problem with Formatting Phone Numbers in Word 2003

A

AmandaH

Ok so here the problem, I know how to set the form field such that it
will produce a phone number in the form (###) ###-#### when the user
enters 10 digits. However what is wanted is that the user will be about
to enter any comin type of phone number and and it will reformatted as
(###) ###-####

Example:

(555) 555-5555 - stays the same
555-555-5555 - becomes (555) 555-5555
555 555-5555 - becomes (555) 555-5555
5555555555 - Becomes (555) 555-5555

The only one I seem to be able to get working is the last one and this
only works when I have the length of the form field set to 10.
Otherwise for all the rest I get an error msg stating that I have an
invalid number.

Is there a way to format this field so that it will take any normally
telephone number style and covert it to (555) 555-5555? A Marco
somewhere?

Thanks,

~Amanda~
 
S

Suzanne S. Barnhill

Do you have the field type set to Number? I have a form set up this way. I
am actually using all hyphens (###-###-####), and I have 000-000-0000 as the
display text. But regardless of whether the user enters 1234567890 or
123-456-7890 or (123) 456-7890 or any other variation, it works fine. I have
the length of the field set to 14 characters so that users who use
parentheses don't get an error message or get booted out prematurely. Both
"Fill-in enabled" and "Calculate on exit" are checked; the format doesn't
change until the user tabs out of the field.
 
A

AmandaH

Thanks, it seems to be working now with the TAB, Mouse and the down/up
arrow keys. However I have it set up that the enter key is assigned to
work as the TAB key and I get the invalid number when I try to use the
enter key to go to the next field. Any ideas?

Here is the code:


Sub EnterKeyMacro()
' Check whether the document is protected for forms
' and whether the protection is active.

If ActiveDocument.ProtectionType = wdAllowOnlyFormFields And _
Selection.Sections(1).ProtectedForForms = True Then
' Retrieve the bookmark of the current selection.
' This is equivalent to the name of the form field.
myformfield = Selection.Bookmarks(1).Name
'sets the enter key equal to the action of the TAB key
SendKeys (" {TAB}")
Else
' If the document is not protected for forms,
' insert a tab stop character.
Selection.TypeText Chr(13)
End If
End Sub

Sub AutoOpen()
' This macro will reassign the ENTER key when you open an existing
' Word form fields document.
CustomizationContext = ActiveDocument.AttachedTemplate
' Bind the Enter key to the EnterKeyMacro.
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryMacro, Command:="EnterKeyMacro"

'Changes the open Document view to PrintView
ActiveWindow.View.Type = wdPrintView
End Sub

Sub AutoClose()
'Release the enter key back to normal
CustomizationContext = ActiveDocument.AttachedTemplate
FindKey(KeyCode:=BuildKeyCode(wdKeyReturn)).Disable
End Sub

Thanks
~Amanda~
 

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