+ Reply to Thread
Results 1 to 2 of 2

looping when checking isdate

  1. #1
    april27
    Guest

    looping when checking isdate

    I use a user form with text box that the user shall write a date in. after
    pressing abutton the info in the textbox shall be investigated in order to
    see that it is a date. if not then display messagebox if otherwise go back to
    user form so that the user can insert new info. i just do not get how to do
    the loop. how do you "go back" in the loop? vb just complains that it is
    private? my code is:

    Private Sub callMainProgramButton_Click()
    strStartDatum = TextBox1.Text
    Call checkDate
    Call mainProgram
    Unload Me
    End Sub

    Private Sub checkDate()
    Worksheets("Setup").Range("a15") = strStartDatum
    If (Not (IsDate(strStartDatum))) Then
    MsgBox "Wrong format"
    Cancel = True
    End If
    End Sub


    As you can see the upper sub calls the lower sub in which isDate is checked.
    however when the sub checkDate() has done one loop i want it to retun
    "somewhere" and get new info from the text field. help!!! please!

  2. #2
    Tom Ogilvy
    Guest

    RE: looping when checking isdate

    why not just use the exit event of the Textbox

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    if not isdate(me.Textbox1.Text) then
    msgbox "Invalid date, try again" & vbNewLine & _
    "Use a format like 08/21/2006"
    me.Textbox1.Text = ""
    Cancel = True
    end if
    End Sub

    --
    Regards,
    Tom Ogilvy

    It would be less confusing to the user if the entry is validated right away.

    --
    Regards,
    Tom Ogilvy


    "april27" wrote:

    > I use a user form with text box that the user shall write a date in. after
    > pressing abutton the info in the textbox shall be investigated in order to
    > see that it is a date. if not then display messagebox if otherwise go back to
    > user form so that the user can insert new info. i just do not get how to do
    > the loop. how do you "go back" in the loop? vb just complains that it is
    > private? my code is:
    >
    > Private Sub callMainProgramButton_Click()
    > strStartDatum = TextBox1.Text
    > Call checkDate
    > Call mainProgram
    > Unload Me
    > End Sub
    >
    > Private Sub checkDate()
    > Worksheets("Setup").Range("a15") = strStartDatum
    > If (Not (IsDate(strStartDatum))) Then
    > MsgBox "Wrong format"
    > Cancel = True
    > End If
    > End Sub
    >
    >
    > As you can see the upper sub calls the lower sub in which isDate is checked.
    > however when the sub checkDate() has done one loop i want it to retun
    > "somewhere" and get new info from the text field. help!!! please!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1