PDA

View Full Version : Solved: If formfield (type=date) is blank then....



petedw
07-22-2005, 02:34 AM
Guys, another quicky for you,

I have the following piece of coding that runs on exit of a formfield called BillDate. The formfields type is a date.
What i want it to do is not let the user exit the formfield unless they have entered a date.
The part of my code that doesnt work is the bit that ends .Result = ""

What should i have in place of the ""

Sub NoBlankDate()
If ActiveDocument.FormFields("BillDate").Result = "" Then
ActiveDocument.FormFields("BillDate").Select
Else
ActiveDocument.FormFields("BillEdition").EntryMacro = "DropDownList"
End If
End Sub

Many Thanks
Pete

MOS MASTER
07-22-2005, 10:36 AM
Hi Pete, :yes

Just for me to understand properly:

You have a date formfield.
If a user leaves that field without entering a valid date (Field does the validation itself) so leaving without any data entered.

Then do not go to the next field but reselect the field you just came from?

Is that what you are looking after?

If so why not fill the field with a date of (Now(), or Date()) so the form is filled in.....?

Please confirm so I can think about a sollution.

HTH, :whistle:

fumei
07-24-2005, 02:19 AM
If the field IS a date type all other errors than "" are caught in Word's internal logic and validation.

The problem lies in the way OnExit and OnEntrence macros work. OnExit fires AFTER the firing of the event that moves to the next field. In othe words:

1. I am done hete in Field A.
2. Go to the next field
3. As I am leaving do this - the procedures in OnExit
4. when finished, finalize #2.

Field A is a date
Enrty is ""
OnExit macro checks for if ""....it is
OnExit macro sets focus back to Field A
OnExit macro exists
Selection move to the next field.

Do an on Entrance for the next field to look BACK.

MOS MASTER
07-24-2005, 11:35 AM
OnExit macro sets focus back to Field A


And that's not as easy at seams! :yes

petedw
07-25-2005, 12:34 AM
Do an on Entrance for the next field to look BACK. That sorted out the problem. :thumb
Cheers guys

Pete

Richardall
07-25-2005, 04:01 AM
If you look in the Word Help Forum you shuld be able to find a calendar moudle that can be linked to your field. When you enter the field, the user will have a choice of using todays date or selecting a date from a pop up calendar. Either way, a data they chose will be entered befors it can move to the next field.

Look in the word forum for a subject Form Field

This may lnk you there; http://www.vbaexpress.com/forum/showthread.php?t=3764&highlight=calendar

Look at the third positng by MosMaster.

Should put you in the game.

Good Luck

MOS MASTER
07-25-2005, 10:42 AM
Hi Richard, :yes

Yes indeed the calendar control (Or a custom version of it (look in KB)) will solve pete's problem as well. (And looks great too) :whistle:

petedw
07-25-2005, 11:51 PM
Certainly does look great. Cheers again

Pete

MOS MASTER
07-26-2005, 09:43 AM
Certainly does look great. Cheers again

Pete

Indeed. If you use the calendar control method you can get rid of the checking code! :yes