Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Validate form field
I have a form field formatted as ####-####-####-#### for a credit card
number. How do I get it to require all 16 digits? If I enter 1234 it will give me 1234--- and keep going. Thanks. Amy |
#2
|
|||
|
|||
Amy,
You can run a macro on exit form the CCNumber field and if the lenght of the string is less than 19 (16 characters plus format spaces) then display a message box and reselect the field. Set the bookmark name of the the credit card number CCNumber and set the following macro to run on exit: Sub ValidateCCNumber() If Len(ActiveDocument.FormFields("CCNumber").Range.Te xt) 19 Then Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="GoBacktoCCNumber" MsgBox "Please enter the full 16 digit number" Else 'Do nothing End If End Sub Sub GoBacktoCCNumber() ActiveDocument.Bookmarks("CCNumber").Range.Fields( 1).Result.Select End Sub -- Greg Maxey/Word MVP See: http://gregmaxey.mvps.org/word_tips.htm For some helpful tips using Word. Amy wrote: I have a form field formatted as ####-####-####-#### for a credit card number. How do I get it to require all 16 digits? If I enter 1234 it will give me 1234--- and keep going. Thanks. Amy |
#3
|
|||
|
|||
Thank you Greg, that works.
For some reason I was thinking that just formatting the number in the properties box would work. Guess not! Thanks for your contributions to this site! "Greg Maxey" wrote: Amy, You can run a macro on exit form the CCNumber field and if the lenght of the string is less than 19 (16 characters plus format spaces) then display a message box and reselect the field. Set the bookmark name of the the credit card number CCNumber and set the following macro to run on exit: Sub ValidateCCNumber() If Len(ActiveDocument.FormFields("CCNumber").Range.Te xt) 19 Then Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="GoBacktoCCNumber" MsgBox "Please enter the full 16 digit number" Else 'Do nothing End If End Sub Sub GoBacktoCCNumber() ActiveDocument.Bookmarks("CCNumber").Range.Fields( 1).Result.Select End Sub -- Greg Maxey/Word MVP See: http://gregmaxey.mvps.org/word_tips.htm For some helpful tips using Word. Amy wrote: I have a form field formatted as ####-####-####-#### for a credit card number. How do I get it to require all 16 digits? If I enter 1234 it will give me 1234--- and keep going. Thanks. Amy |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Text form field inside a WORD table cell, odd behavior when select | Tables | |||
Text form field inside WORD table cell, odd selection behavior | Microsoft Word Help | |||
Form Field Formatting | Microsoft Word Help | |||
Enter data in 1 text form field & have multiple locations fill | Microsoft Word Help | |||
Text Form Field Ref in Footer Won't Update on Screen | Microsoft Word Help |