![]() |
#1
|
|||
|
|||
![]()
I have two legacy control fields "Begin" and "End" in a Word 2007 form. I defined the type as "Date" in the text form field options. I was hoping to write a macro that would run on exit from the End date to warn the user if the End date is before the Begin date. I'm not having much luck. I finally had the macro output a message box with the value in the date fields, and no matter the date, the value is always 70.
Am I trying to do something that isn't possible, or am I just too much of a newbie at VBA to figure out how to do it? Here's what I was trying to do: Sub End_Date() ' ' End_Date Macro ' ' If ActiveDocument.FormFields("End") <= ActiveDocument.FormFields("Begin") Then MsgBox "Term ending date must be after beginning date." End If End Sub Thanks, Joe |
#2
|
||||
|
||||
![]()
You can actually do this without a macro, using field coding to conditionally display a message in the body of the document. The field code would be:
{IF {End \@ YYYYMMDD} > {Begin\@ YYYYMMDD} "" "Term ending date must be after beginning date."} Simply check the formfields' 'calculate on exit' property. Some additional field coding could be used to suppress the message when either field is empty. Note: The field brace pairs (ie '{ }') for the above example are created in the body of the document via Ctrl-F9 (Cmd-F9 on a Mac) - you can't simply type them or copy & paste them from this message.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
If you want to still use a macro, try:
Code:
Sub End_Date() Dim myEnd As Date Dim myStart As Date myEnd = ActiveDocument.FormFields("End").Result myStart = ActiveDocument.FormFields("Begin").Result If myEnd <= myStart Then MsgBox "Term ending date must be after beginning date." End If End Sub |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Berk21 | Excel | 9 | 02-03-2012 12:19 PM |
Using legacy forms with text boxes? Any way around this? | svengoolie | Word | 1 | 02-01-2012 11:53 AM |
![]() |
skarden | Word | 1 | 12-12-2011 10:39 PM |
Can't open .pst legacy files | RetiredEngineer | Outlook | 1 | 11-14-2009 01:06 PM |
Templates: automatic text generation from Rich Text content control | Chickenmunga | Word | 0 | 10-01-2008 11:16 AM |