Consulting

Results 1 to 9 of 9

Thread: Solved: If formfield (type=date) is blank then....

  1. #1
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location

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

    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 ""

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

    Many Thanks
    Pete

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Pete,

    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,
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by fumei
    OnExit macro sets focus back to Field A
    And that's not as easy at seams!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #5
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location
    Do an on Entrance for the next field to look BACK.
    That sorted out the problem.
    Cheers guys

    Pete

  6. #6

    Try this

    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/show...light=calendar

    Look at the third positng by MosMaster.

    Should put you in the game.

    Good Luck

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Richard,

    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)
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  8. #8
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location
    Certainly does look great. Cheers again

    Pete

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by petedw
    Certainly does look great. Cheers again

    Pete
    Indeed. If you use the calendar control method you can get rid of the checking code!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •