Text Form Field

R

rob p

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.
 
H

Helmut Weber

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/
 
J

Jay Freedman

rob said:
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.
 

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