Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2013, 11:09 AM
JoeE JoeE is offline Comparing dates in legacy control text box Windows XP Comparing dates in legacy control text box Office 2007
Novice
Comparing dates in legacy control text box
 
Join Date: Apr 2013
Location: Louisville, KY
Posts: 1
JoeE is on a distinguished road
Default Comparing dates in legacy control text box

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
Reply With Quote
  #2  
Old 05-08-2013, 03:19 PM
macropod's Avatar
macropod macropod is offline Comparing dates in legacy control text box Windows 7 64bit Comparing dates in legacy control text box Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 05-08-2013, 11:01 PM
fumei fumei is offline Comparing dates in legacy control text box Windows 7 64bit Comparing dates in legacy control text box Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing dates in legacy control text box Comparing 2 columns of Text 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
Comparing dates in legacy control text box Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft