Validate form field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.Text) < 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
 
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!
 
Back
Top