Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a date mask for a Word form field, can it be done? 1

Status
Not open for further replies.

Lee1955

Technical User
Feb 10, 2005
2
US
Hi,
The boss wants a new form template in MS Word for distribution around the department. He wants people to be able to type in 030409 and see 3/4/09 in the document. Since this form asks for 22 dates, it would certainly be a time saver for workers. Can anybody tell me if this can be done, and how?

Thanks,

Lee
 
Hi Lee,

You could use a function like:
Code:
Function StrToDate(FFname As String) As String
Dim TmpStr
TmpStr = ActiveDocument.FormFields(FFname).Result
If Len(TmpStr) = 6 Then
  If CDate(Left(TmpStr, 2) & "/" & Mid(TmpStr, 3, 2) & "/" & Right(TmpStr, 2)) Then
    StrToDate = Format(CDate(Left(TmpStr, 2) & "/" & Mid(TmpStr, 3, 2) & "/" & Right(TmpStr, 2)), "DD-MM-YYYY")
  Else
    StrToDate = TmpStr
  End If
Else
  StrToDate = TmpStr
End If
End Function
which you could call with an 'On Exit' macro like:
Code:
Sub Date1()
Dim StrFNm As String
StrFNm = "Date1"
ActiveDocument.FormFields(StrFNm).Result = StrToDate(StrFNm)
End Sub
Attached to each of the date formfields. With the sub, you'd need one per formfield, where 'Date1' is the sub's name, the StrFNm parameter and the formfield's bookmark name.

Cheers

[MS MVP - Word]
 
Worked like a charm.

Thanks a bunch!!!!

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top