Form - required field(s) valid date

  • Thread starter Michael M via OfficeKB.com
  • Start date
M

Michael M via OfficeKB.com

Hello,

I've created a form and need to make the first field (Text15) require that
the user enter a valid date, without bypassing it or leaving it blank.

I have modified the properties of the text box so that it's type is Date and
set it's Date Format, however in testing I have found that if the user does
not enter anything in the field, there is no way to require a valid date be
entered, that is only if I enter text or something else invalid.

Thank you,
Michael
 
J

Jay Freedman

Michael said:
Hello,

I've created a form and need to make the first field (Text15) require
that the user enter a valid date, without bypassing it or leaving it
blank.

I have modified the properties of the text box so that it's type is
Date and set it's Date Format, however in testing I have found that
if the user does not enter anything in the field, there is no way to
require a valid date be entered, that is only if I enter text or
something else invalid.

Thank you,
Michael

See http://word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm.
 
M

Michael M via OfficeKB.com

Suzanne,

Thank you for the link, I did actually find that earlier and have attempted
to use that macro, but it does not work for me?

I see no change when I enter the form or the field, I am using Word XP. How
should I be entering this as a new macro, from the Tools > Macros > Macros >
Create and I pasted this;

Sub ExitText2()
With ActiveDocument.FormFields("Text2")
If Len(.Result) > 0 And Left$(.Result, 3) <> "KLM" Then
Application.OnTime When:=Now + TimeValue("00:00:01"), Name:
="GoBacktoText2"
MsgBox "The first three letters must be 'KLM'"
End If
End With
End Sub

Sub GoBacktoText2()
ActiveDocument.Bookmarks("Text2").Range.Fields(1).Result.Select
End Sub

Modifying it for my field "Text15" but it does not do anything? I notice no
change at all ... should this be selected as the "entry" or "exit" macro?

Thank you,
Michael
 
J

Jay Freedman

Hi Michael,

Item 1: Select this macro as the exit macro for your field.

Item 2: Make sure you change "Text2" to "Text15" in all five places where it
occurs.

Item 3: You need to change the "If" statement (the third line of the
ExitText2 macro). The macro as you copied it from the web page is only an
example of the kind of thing you can do, and this particular example is
checking to be sure the field contents start with the letters KLM -- not
what you want. To check that the field is not empty, that line should be
replaced by

If Len(.Result) = 0 Then

You'll also want to change the message in the MsgBox statement to something
like "The date field cannot be blank".

--
Regards,
Jay Freedman
Microsoft Word MVP
Suzanne,

Thank you for the link, I did actually find that earlier and have
attempted to use that macro, but it does not work for me?

I see no change when I enter the form or the field, I am using Word
XP. How should I be entering this as a new macro, from the Tools >
Macros > Macros > Create and I pasted this;

Sub ExitText2()
With ActiveDocument.FormFields("Text2")
If Len(.Result) > 0 And Left$(.Result, 3) <> "KLM" Then
Application.OnTime When:=Now + TimeValue("00:00:01"),
Name: ="GoBacktoText2"
MsgBox "The first three letters must be 'KLM'"
End If
End With
End Sub

Sub GoBacktoText2()
ActiveDocument.Bookmarks("Text2").Range.Fields(1).Result.Select
End Sub

Modifying it for my field "Text15" but it does not do anything? I
notice no change at all ... should this be selected as the "entry" or
"exit" macro?

Thank you,
Michael
 
M

Michael M via OfficeKB.com

Thank you! That works beautifully, and I have made slight additions/changes
to it.

Thanks again!


Jay said:
Hi Michael,

Item 1: Select this macro as the exit macro for your field.

Item 2: Make sure you change "Text2" to "Text15" in all five places where it
occurs.

Item 3: You need to change the "If" statement (the third line of the
ExitText2 macro). The macro as you copied it from the web page is only an
example of the kind of thing you can do, and this particular example is
checking to be sure the field contents start with the letters KLM -- not
what you want. To check that the field is not empty, that line should be
replaced by

If Len(.Result) = 0 Then

You'll also want to change the message in the MsgBox statement to something
like "The date field cannot be blank".
[quoted text clipped - 33 lines]
 

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