I am making a template in Word 2000. I am using text form fields. I need
further formatting for two types of form fields than it seems I can get thru
the form field options.

One, I want a number mask like a SSN. ###-##-####. Enter nine numbers and it
adds the dashes.

Two, using regular text, I want one character to be entered, only selecting
from the characters A,B, or C. Anything else won't work.

Is there any way to set this up?
Thanks.

Re: Text Form Field by Helmut

Helmut
Wed Dec 08 14:00:55 CST 2004

Hi Rob,
as for 2, use a listbox.
As for 1, like this:

Sub Exit01()
Dim i As Integer
With ActiveDocument.FormFields(1)
If Len(.Result) = 9 Then
For i = 1 To 9
If Not Mid(.Result, i, 1) Like "#" Then
GoTo Noway
End If
Next
Else
GoTo Noway
End If
.Result = "SSN. " & Format(.Result, "000-00-0000")
Exit Sub
Noway:
MsgBox "goback and try again"
.Result = "9 digits please"
.Select
End With
End Sub

And for the theory:
In theoretical linguistics a set of rules that defines allowed
sequences of characters, is called a grammar.
So, that was defining a grammar for "result", hopefully.
Telling the user, what was wrong, is quite another story.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/

Re: Text Form Field by rob

rob
Wed Dec 08 14:30:22 CST 2004

Thanks much Helmut.
Rob

"Helmut Weber" <elmkqznfwvccbf@mailinator.com> wrote in message
news:jmmer0da5r86mgaoum7ani9ufqc8m0erd3@4ax.com...
> Hi Rob,
> as for 2, use a listbox.
> As for 1, like this:
>
> Sub Exit01()
> Dim i As Integer
> With ActiveDocument.FormFields(1)
> If Len(.Result) = 9 Then
> For i = 1 To 9
> If Not Mid(.Result, i, 1) Like "#" Then
> GoTo Noway
> End If
> Next
> Else
> GoTo Noway
> End If
> .Result = "SSN. " & Format(.Result, "000-00-0000")
> Exit Sub
> Noway:
> MsgBox "goback and try again"
> .Result = "9 digits please"
> .Select
> End With
> End Sub
>
> And for the theory:
> In theoretical linguistics a set of rules that defines allowed
> sequences of characters, is called a grammar.
> So, that was defining a grammar for "result", hopefully.
> Telling the user, what was wrong, is quite another story.
>
> Greetings from Bavaria, Germany
> Helmut Weber, MVP
> "red.sys" & chr(64) & "t-online.de"
> Word XP, Win 98
> http://word.mvps.org/



Re: Text Form Field by Jay

Jay
Wed Dec 08 14:44:15 CST 2004

rob p wrote:
> I am making a template in Word 2000. I am using text form fields. I
> need further formatting for two types of form fields than it seems I
> can get thru the form field options.
>
> One, I want a number mask like a SSN. ###-##-####. Enter nine numbers
> and it adds the dashes.
>
> Two, using regular text, I want one character to be entered, only
> selecting from the characters A,B, or C. Anything else won't work.
>
> Is there any way to set this up?
> Thanks.

Hi Rob,

You can do it with macros or with a Userform (custom dialog built in VBA)
but not with form fields alone.

One way is to write a macro that inserts the dashes in the SSN field (or
displays an error message if the field doesn't contain exactly 9 digits),
and set that as the field's exit macro. Similarly, you could write an exit
macro for the other field that complains if the field content isn't A, B, or
C. See http://word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm.

The second field could be replaced with a dropdown that allows only a choice
of the three items.

Or you could create a Userform that contains controls for both entries, with
code behind it to validate and format the user's entry. This is slicker but
a bit more work. See
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org