#1   Report Post  
Amy
 
Posts: n/a
Default 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   Report Post  
Greg Maxey
 
Posts: n/a
Default

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   Report Post  
Amy
 
Posts: n/a
Default

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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Text form field inside a WORD table cell, odd behavior when select pwrichcreek Tables 9 October 20th 05 12:34 AM
Text form field inside WORD table cell, odd selection behavior pwrichcreek Microsoft Word Help 1 October 11th 05 03:57 PM
Form Field Formatting Leslie Microsoft Word Help 3 June 14th 05 03:06 PM
Enter data in 1 text form field & have multiple locations fill Lee Microsoft Word Help 1 March 16th 05 11:56 PM
Text Form Field Ref in Footer Won't Update on Screen StarWine Microsoft Word Help 3 December 6th 04 07:17 PM


All times are GMT +1. The time now is 03:15 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"