Word Form Template
Solved
CHATOUNETTE
-
CLOWNELLE Posted messages 26 Status Member -
CLOWNELLE Posted messages 26 Status Member -
Good evening,
I was creating a form in Word and I'm having trouble with the label Phone Number. How can I make it so that when a person enters their number, it displays in chunks of 2 digits separated by a space for the 10 digits, like this (00 00 00 00 00)? Also, for the label Social Security Number, how can I make it so that spaces are automatically inserted between the digits (like this: 0 00 00 00 000 000 00)?
I'm working from home (due to confinement) and I would like to make progress on this form creation. Thank you for your insights!
I was creating a form in Word and I'm having trouble with the label Phone Number. How can I make it so that when a person enters their number, it displays in chunks of 2 digits separated by a space for the 10 digits, like this (00 00 00 00 00)? Also, for the label Social Security Number, how can I make it so that spaces are automatically inserted between the digits (like this: 0 00 00 00 000 000 00)?
I'm working from home (due to confinement) and I would like to make progress on this form creation. Thank you for your insights!
6 answers
-
Hello,
You mention a form, but we don't know what type of form you're referring to. There are at least three kinds. So, what you want to do is possible, but it depends on the controls used.
https://faqword.com/index.php/word/formulaires-controles/911-le-point-sur-les-outils-de-formulaires
m@rina
--
At least half of the users ask a question and never come back. Sometimes I wonder why I keep responding...-
Good evening,
I am in Creation Mode, Custom with text fields "Properties", drop-down lists, calendar. So a form filled out on the computer. At one point, I want people to enter their social security number, phone number. I would like a formatting with spaces and not a succession of digits. Thank you for the link. Best regards. Sandra. -
Hello,
You don't respond very clearly regarding the given link...
Well, it seems that it's about content controls.
What you want to do is only possible through a macro.
Here is a macro that will format the social security number and the phone number. You need to start by assigning tags to your two controls (through properties). In my example, it's "sécu" and "tél". Place this macro in ThisDocument:
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim nsecu, ntel
If CC.Tag = "sécu" Then
nsecu = CC.Range.Text
nsecu = Format(nsecu, "0 00 00 00 000 000 00")
CC.Range = nsecu
End If
If CC.Tag = ("tél") Then
ntel = CC.Range.Text
ntel = Format(ntel, "00 00 00 00 00")
CC.Range = ntel
End If
End Sub
I show here how to place this macro
https://faqword.com/index.php/word/formulaires-controles/902-a-l-instar-des-champs-de-formulaire-peut-on-declencher-une-macro-a-la-sortie-d-un-controle-de-contenu?highlight=WyJjb250ZW50Y29udHJvbCJd
It should be noted that the formatting will occur once we exit the control since the event is EXIT.
For your protection issue, make sure to choose Form Protection and only the controls will be fillable.
m@rina -
Hello Marina, under "Developer", I indeed inserted under "Aa" (Plain Text Content Control). I did Alt+F11 and entered the macro. I saved it correctly. In "Properties", I specified the word "tél" in the "Tag" line for the corresponding line, and in another plain text content control, I specified the tag "sécu". I restricted editing by selecting "Filling in forms", and I saved it.
The problem is that when the person reaches the phone number line or the security line, it shows: "Click or tap here to enter text" and when the phone number is entered, this text does not disappear. As a result, the number is mixed in with the text "click or tap here...". I don’t understand, especially since for the other cells where this same text is present, when the information is entered, this text disappears to make way for the information entered by the person filling out the form. Where could this be coming from?
A big THANK YOU, Marina, for this macro. I'm starting to get to the heart of the matter!
Sandra -
Hello Sandra
To insert a prompt message, you need to switch to Creation mode and type the message. Then, once you exit Creation mode, clicking in the content will make the message disappear.
In fact, there was a small issue in the macro, as it was also formatting the label. I'm attaching the document here with the corrected macros
https://www.cjoint.com/doc/20_03/JCBn1Z2OkrH_format-cc.docm
m@rina -
Marina, I see that you are much more comfortable than I am. I'm already very happy to have managed to put your explanations into practice for the macro. I've taken screenshots so you can visualize better what I have on my screen, but how can I send them to you (how did you do above to put the macro in?)
-
-
Hello.
Solution 1 = Create the form in Excel, not in Word.
Solution 2 = Insert tables with one row and 14 columns for the phone, one row and 21 columns for the SS.
https://www.cjoint.com/c/JCzboGpVIu7
--
Retirement is great! Especially in the Antilles...
Raymond (INSA, AFPA)-
Hello,
Thank you for this information.
However, in the forms, I have already seen that when you type the number, the spaces automatically move to the next box, allowing only one digit per box.
Still in my form, at the end, I protected it with a password, and when I test it, my titles remain editable. You can write in them. Could you provide me with an explanation that might help?
Thank you in advance.
-
-
Good evening Marina,
To finish with the previous macro. When more than 10 digits are entered in the phone number or an extra digit for the social security number (which is currently possible), I would like to know if it is possible to insert a command in the macro that displays an error message informing that there is one digit too many.
Is it possible or not?
Thank you again. -
Hello,
It is important to know that the possibilities in a content control are quite limited, unlike Userform controls or even ActiveX.
As you understood, the events are limited: you can only perform an action when entering and leaving the control.
I immediately eliminate the message on entry that explains what needs to be done and will quickly annoy everyone.
On exit, we can check the number of characters, we can also check if it is numeric. The problem is that spaces are considered part of the numeric format. And if the person enters spaces, it will generate an error...
I am thinking about what can be done and I will get back to you.
m@rina
--
At least half of the users ask a question and never return. Sometimes I wonder why I keep answering... -
Re...
Here is a macro that cancels and replaces the first one. So, go into your macros and completely delete the existing macro.
This macro will check the number of digits entered, regardless of whether the person has typed spaces or not. If the number is correct (10 for the phone number and 15 for the social security number), the number will be formatted; otherwise, there will be a message (which you can modify if necessary). If the person has entered spaces, it's not a problem, but we can warn them that it's unnecessary.
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim texte As String, i, Result, nb
texte = CC.Range.Text
If CC.ShowingPlaceholderText = False Then
If Not IsNumeric(texte) Then GoTo fin:
Select Case CC.Tag
Case "tél"
For i = 1 To Len(texte)
If IsNumeric(Mid(texte, i, 1)) Then
Result = Result & Mid(texte, i, 1)
End If
Next
CC.Range = Result
nb = CC.Range.Characters.Count
If nb <> 10 Then
MsgBox "the number is incorrect, it must contain 10 digits"
Else: texte = Format(texte, "0# ## ## ## ##")
CC.Range = texte
End If
Case "sécu"
For i = 1 To Len(texte)
If IsNumeric(Mid(texte, i, 1)) Then
Result = Result & Mid(texte, i, 1)
End If
Next
CC.Range = Result
nb = CC.Range.Characters.Count
If nb <> 15 Then
MsgBox "the number is incorrect, it must contain 15 digits"
Else: texte = Format(texte, "0 00 00 00 000 000 00")
CC.Range = texte
End If
End Select
End If
Exit Sub
fin: MsgBox "Incorrect number"
End Sub
--
At least half the users ask a question and never come back. Sometimes I wonder why I keep answering...-
I made an article about it because it's a question that should interest quite a few users. See here:
https://faqword.com/index.php/word/formulaires-controles/1111
-
-
IT WORKS!!!!!!
It's great that you created an article on the subject.
You're a genius, I will tell my director that this led to the creation of an article.
Looking forward to it.
Sandra