+ Reply to Thread
Results 1 to 4 of 4

userform-check data type

Hybrid View

Guest userform-check data type 03-28-2005, 10:06 AM
Guest Re: userform-check data type 03-28-2005, 11:06 AM
Guest Re: userform-check data type 03-28-2005, 11:06 AM
Guest Re: userform-check data type 03-28-2005, 11:06 AM
  1. #1
    xlcharlie
    Guest

    userform-check data type

    I am developing a userform in which the user will enter a date. I want the
    code to verify that the data entered is a valid date (type dbDate) before
    calling the procedure. To do this I have been working with the code below:
    Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim dtHol As Variant
    dtHol = TextBox1.Value
    If TextBox1.Type <> dbDate And TextBox1.Value <> "" Or _
    TextBox1.Value <> 0 Then
    Call errMsg1
    End If
    End Sub

    The Type method does not seem to be available for this purpose, and
    assigning a variable the value of the TextBox has been similarly
    unsuccessful. Any hints how this should be done?

  2. #2
    Tom Ogilvy
    Guest

    Re: userform-check data type

    A textbox returns a string, so you can't test the type property (which a
    textbox doesn't have a type property) against any constant. A constant such
    as dbDate must be defined in a library other than Excel, Officer or MSForms,
    so it would have little utility in such a check if it were possible.

    Dim dt as Date
    on Error Resume Next
    dt = cDate(Textbox1.Text)
    On Error goto 0

    now check out dt to see if it meets your criteria.

    --
    Regards,
    Tom Ogilvy



    "xlcharlie" <xlcharlie@discussions.microsoft.com> wrote in message
    news:8DFB6CE5-6E3B-4FEA-82F2-63228A144A91@microsoft.com...
    > I am developing a userform in which the user will enter a date. I want

    the
    > code to verify that the data entered is a valid date (type dbDate) before
    > calling the procedure. To do this I have been working with the code

    below:
    > Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    > Dim dtHol As Variant
    > dtHol = TextBox1.Value
    > If TextBox1.Type <> dbDate And TextBox1.Value <> "" Or _
    > TextBox1.Value <> 0 Then
    > Call errMsg1
    > End If
    > End Sub
    >
    > The Type method does not seem to be available for this purpose, and
    > assigning a variable the value of the TextBox has been similarly
    > unsuccessful. Any hints how this should be done?




  3. #3
    Bob Phillips
    Guest

    Re: userform-check data type


    If Not IsDate(TextBox1.Text) And TextBox1.Value <> "" Or _
    TextBox1.Value <> 0 Then


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "xlcharlie" <xlcharlie@discussions.microsoft.com> wrote in message
    news:8DFB6CE5-6E3B-4FEA-82F2-63228A144A91@microsoft.com...
    > I am developing a userform in which the user will enter a date. I want

    the
    > code to verify that the data entered is a valid date (type dbDate) before
    > calling the procedure. To do this I have been working with the code

    below:
    > Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    > Dim dtHol As Variant
    > dtHol = TextBox1.Value
    > If TextBox1.Type <> dbDate And TextBox1.Value <> "" Or _
    > TextBox1.Value <> 0 Then
    > Call errMsg1
    > End If
    > End Sub
    >
    > The Type method does not seem to be available for this purpose, and
    > assigning a variable the value of the TextBox has been similarly
    > unsuccessful. Any hints how this should be done?




  4. #4
    Michael Malinsky
    Guest

    Re: userform-check data type

    Try this:

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    Dim dtHol As Variant
    Dim dbDate As Date

    dtHol = TextBox1.Value
    If IsDate(TextBox1) <> True And (TextBox1.Value <> "" Or _
    TextBox1.Value <> 0) Then
    MsgBox "Value must be date (mm/dd/yyyy)."
    Cancel = True
    End If

    End Sub


    "xlcharlie" <xlcharlie@discussions.microsoft.com> wrote in message
    news:8DFB6CE5-6E3B-4FEA-82F2-63228A144A91@microsoft.com...
    > I am developing a userform in which the user will enter a date. I want

    the
    > code to verify that the data entered is a valid date (type dbDate) before
    > calling the procedure. To do this I have been working with the code

    below:
    > Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    > Dim dtHol As Variant
    > dtHol = TextBox1.Value
    > If TextBox1.Type <> dbDate And TextBox1.Value <> "" Or _
    > TextBox1.Value <> 0 Then
    > Call errMsg1
    > End If
    > End Sub
    >
    > The Type method does not seem to be available for this purpose, and
    > assigning a variable the value of the TextBox has been similarly
    > unsuccessful. Any hints how this should be done?




+ 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