• Validate date in field (WIN 95 Word 97)

    Author
    Topic
    #382882

    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.Fields(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?

    Viewing 0 reply threads
    Author
    Replies
    • #650963

      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.

      • #651239

        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.Fields(1).Result.Select
        Exit Sub
        End If

        Many thanks,

        David

        • #651787

          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

          • #654158

            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

            • #654238

              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

    Viewing 0 reply threads
    Reply To: Validate date in field (WIN 95 Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: