Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validate date in field (WIN 95 Word 97)

    Having a bit of trouble here. I have a date entry field at the end of a form. The field is set to "date only" and would normally validate ok when the user tabbed to the next field.

    The form is e-mailed using a command button in a text box - the button runs a mailing macro.

    I have found that you can write rubbish in the date field and because no tab occurrs when the command button is pressed, the field is not validated. So I thought I would force a tab by selecting the date field and tabbing to another field. These two lines are the first in the mailing sub:

    ActiveDocument.Bookmarks("disposal_date").Range.Fi elds(1).Result.Select
    SendKeys "{tab}"

    I hve put another empty field after the date field and I hoped that tabbing out of the date field would force the validation. However, I cannot get the SendKeys to work. The field is selected okay but no tabbing happens.

    Any ideas please?

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Validate date in field (WIN 95 Word 97)

    You could put the validate code for that date field (and any other for that matter) in a sub called by your command button.
    That should work.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Validate date in field (WIN 95 Word 97)

    Hello Kevin,

    I was running the code off the command button but a Google search unearthed IsDate so I have used that and it works okay:

    Dim test_date
    test_date = ActiveDocument.FormFields("disposal_date").Result

    If Not IsDate(test_date) Then
    MsgBox "Please enter a valid date", vbCritical & vbOKOnly, "Error"
    ActiveDocument.Bookmarks("disposal_date").Range.Fi elds(1).Result.Select
    Exit Sub
    End If

    Many thanks,

    David

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Validate date in field (WIN 95 Word 97)

    David,

    I'm not sure if a general solution has been arrived at here but I'm writing bcs I'm interested in knowing if there is one.

    Suppose I'm NOT emailing the form so I don't have a command button to do this and, hence, no macro to email where I stick in the validation code. The OnExit macro for the field, which would do the validation, is not triggered since I never exit. I may save the file, etc. So how would the validation for the last field get done?

    Was the code you posted with IsDate in your command button (or its macro)? If so, where would one include this code if not mailing? You mentioned the alternative of creating a "dummy" field and using SendKeys to get to it. But even this, I assume, was in your email command button.

    Fred

  5. #5
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Validate date in field (WIN 95 Word 97)

    Hello Fred,

    Sorry for delay in reply - just back from Provence. Very cold but sunny.

    I ran the IsDate code as part of the email macro that was triggered by the "Email this Form" command button at the top of the form. I could never get SendKeys to work.

    If you are not e-mailing the form I presume you are either printing it straight off and/or saving to the users harddrive so I would put a command button next to the last field. The button would either print or offer the save dialogue. You could run the validation macro from that.

    You could also leave the last field as a field that does not require validation. That was my easy option (move the date field to the beginning of the form so that the user would tab out of it) but the other validation processes used field numbers and I could not face the thought of sorting all the numbers out again in the macro.

    However I do not know of any way to validate a last field if the user just saves from the File drop-down. I think we need Kevin or Hans here!

    Regards,

    David

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Validate date in field (WIN 95 Word 97)

    Thanks Dave.

    So the answer is think about your form layout, including validations, before going very far.

    No delays here. We have a blizzard going since last night. Already have about 12 inches of snow on the ground since yesterday afternoon. And it's continuing throughout the day today. So I'm at home today. Tomorrow...?

    Fred

Posting Permissions

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