+ Reply to Thread
Results 1 to 7 of 7

Formatting a text box for date entry only

  1. #1
    Claus Mygind
    Guest

    Formatting a text box for date entry only

    Is there a way to format a text box on a user form to only allow date
    entries ie: mm/dd/yy or mm/dd/yyyy?



  2. #2
    Bob Phillips
    Guest

    Re: Formatting a text box for date entry only

    Not really, but you can ensure it is a date, like so

    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim fValid As Boolean

    fValid = False
    On Error GoTo ws_exit
    Application.EnableEvents = False
    If Not Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
    With Target
    If IsNumeric(.Value) Then
    If IsDate(.Value) Then
    If Year(.Value) >= 1970 And Year(.Value) <= 2999 Then
    fValid = True
    End If
    End If
    End If
    If Not fValid Then
    MsgBox "Invalid value"
    .Value = ""
    End If
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub

    'This is worksheet event code, which means that it needs to be
    'placed in the appropriate worksheet code module, not a standard
    'code module. To do this, right-click on the sheet tab, select
    'the View Code option from the menu, and paste the code in.


    You can tune the limits.

    --
    HTH

    Bob Phillips

    "Claus Mygind" <[email protected]> wrote in message
    news:%[email protected]...
    > Is there a way to format a text box on a user form to only allow date
    > entries ie: mm/dd/yy or mm/dd/yyyy?
    >
    >




  3. #3
    Dave Peterson
    Guest

    Re: Formatting a text box for date entry only

    The subject says a textbox--but it doesn't give a hint about where that textbox
    is--on a worksheet or on a userform.

    And if it's on a worksheet, it doesn't say if it's a textbox from the drawing
    toolbar or from the Control toolbox toolbar.

    ==
    To the OP, you may want to look at using a calendar control.

    There's a link to a free calendar control at the bottom of Ron de Bruin's page:
    http://www.rondebruin.nl/calendar.htm

    Ron has some instructions on how to use it on that same page.



    Bob Phillips wrote:
    >
    > Not really, but you can ensure it is a date, like so
    >
    > Option Explicit
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim fValid As Boolean
    >
    > fValid = False
    > On Error GoTo ws_exit
    > Application.EnableEvents = False
    > If Not Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
    > With Target
    > If IsNumeric(.Value) Then
    > If IsDate(.Value) Then
    > If Year(.Value) >= 1970 And Year(.Value) <= 2999 Then
    > fValid = True
    > End If
    > End If
    > End If
    > If Not fValid Then
    > MsgBox "Invalid value"
    > .Value = ""
    > End If
    > End With
    > End If
    >
    > ws_exit:
    > Application.EnableEvents = True
    > End Sub
    >
    > 'This is worksheet event code, which means that it needs to be
    > 'placed in the appropriate worksheet code module, not a standard
    > 'code module. To do this, right-click on the sheet tab, select
    > 'the View Code option from the menu, and paste the code in.
    >
    > You can tune the limits.
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > "Claus Mygind" <[email protected]> wrote in message
    > news:%[email protected]...
    > > Is there a way to format a text box on a user form to only allow date
    > > entries ie: mm/dd/yy or mm/dd/yyyy?
    > >
    > >


    --

    Dave Peterson

  4. #4
    Claus Mygind
    Guest

    Re: Formatting a text box for date entry only

    Dave
    Thanks for the input. I did specify that the text box was on a user form.
    But I like the information with the calander picker. I am going to see if I
    can work that in. Thanks for the response. For a quick fix I may use Bob's
    example as I see I can plug that in fairly easily.

    Claus


    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    > The subject says a textbox--but it doesn't give a hint about where that

    textbox
    > is--on a worksheet or on a userform.
    >
    > And if it's on a worksheet, it doesn't say if it's a textbox from the

    drawing
    > toolbar or from the Control toolbox toolbar.
    >
    > ==
    > To the OP, you may want to look at using a calendar control.
    >
    > There's a link to a free calendar control at the bottom of Ron de Bruin's

    page:
    > http://www.rondebruin.nl/calendar.htm
    >
    > Ron has some instructions on how to use it on that same page.
    >
    >
    >
    > Bob Phillips wrote:
    > >
    > > Not really, but you can ensure it is a date, like so
    > >
    > > Option Explicit
    > >
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > Dim fValid As Boolean
    > >
    > > fValid = False
    > > On Error GoTo ws_exit
    > > Application.EnableEvents = False
    > > If Not Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
    > > With Target
    > > If IsNumeric(.Value) Then
    > > If IsDate(.Value) Then
    > > If Year(.Value) >= 1970 And Year(.Value) <= 2999

    Then
    > > fValid = True
    > > End If
    > > End If
    > > End If
    > > If Not fValid Then
    > > MsgBox "Invalid value"
    > > .Value = ""
    > > End If
    > > End With
    > > End If
    > >
    > > ws_exit:
    > > Application.EnableEvents = True
    > > End Sub
    > >
    > > 'This is worksheet event code, which means that it needs to be
    > > 'placed in the appropriate worksheet code module, not a standard
    > > 'code module. To do this, right-click on the sheet tab, select
    > > 'the View Code option from the menu, and paste the code in.
    > >
    > > You can tune the limits.
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > "Claus Mygind" <[email protected]> wrote in message
    > > news:%[email protected]...
    > > > Is there a way to format a text box on a user form to only allow date
    > > > entries ie: mm/dd/yy or mm/dd/yyyy?
    > > >
    > > >

    >
    > --
    >
    > Dave Peterson




  5. #5
    Dave Peterson
    Guest

    Re: Formatting a text box for date entry only

    Yes, you did have that userform note. I missed it.

    You will have to move Bob's code to a different procedure, though, right?

    Maybe the "TextBox1_Exit" procedure?



    Claus Mygind wrote:
    >
    > Dave
    > Thanks for the input. I did specify that the text box was on a user form.
    > But I like the information with the calander picker. I am going to see if I
    > can work that in. Thanks for the response. For a quick fix I may use Bob's
    > example as I see I can plug that in fairly easily.
    >
    > Claus
    >
    > "Dave Peterson" <[email protected]> wrote in message
    > news:[email protected]...
    > > The subject says a textbox--but it doesn't give a hint about where that

    > textbox
    > > is--on a worksheet or on a userform.
    > >
    > > And if it's on a worksheet, it doesn't say if it's a textbox from the

    > drawing
    > > toolbar or from the Control toolbox toolbar.
    > >
    > > ==
    > > To the OP, you may want to look at using a calendar control.
    > >
    > > There's a link to a free calendar control at the bottom of Ron de Bruin's

    > page:
    > > http://www.rondebruin.nl/calendar.htm
    > >
    > > Ron has some instructions on how to use it on that same page.
    > >
    > >
    > >
    > > Bob Phillips wrote:
    > > >
    > > > Not really, but you can ensure it is a date, like so
    > > >
    > > > Option Explicit
    > > >
    > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > Dim fValid As Boolean
    > > >
    > > > fValid = False
    > > > On Error GoTo ws_exit
    > > > Application.EnableEvents = False
    > > > If Not Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
    > > > With Target
    > > > If IsNumeric(.Value) Then
    > > > If IsDate(.Value) Then
    > > > If Year(.Value) >= 1970 And Year(.Value) <= 2999

    > Then
    > > > fValid = True
    > > > End If
    > > > End If
    > > > End If
    > > > If Not fValid Then
    > > > MsgBox "Invalid value"
    > > > .Value = ""
    > > > End If
    > > > End With
    > > > End If
    > > >
    > > > ws_exit:
    > > > Application.EnableEvents = True
    > > > End Sub
    > > >
    > > > 'This is worksheet event code, which means that it needs to be
    > > > 'placed in the appropriate worksheet code module, not a standard
    > > > 'code module. To do this, right-click on the sheet tab, select
    > > > 'the View Code option from the menu, and paste the code in.
    > > >
    > > > You can tune the limits.
    > > >
    > > > --
    > > > HTH
    > > >
    > > > Bob Phillips
    > > >
    > > > "Claus Mygind" <[email protected]> wrote in message
    > > > news:%[email protected]...
    > > > > Is there a way to format a text box on a user form to only allow date
    > > > > entries ie: mm/dd/yy or mm/dd/yyyy?
    > > > >
    > > > >

    > >
    > > --
    > >
    > > Dave Peterson


    --

    Dave Peterson

  6. #6
    Registered User
    Join Date
    02-13-2005
    Posts
    64
    Quote Originally Posted by Dave Peterson
    There's a link to a free calendar control at the bottom of Ron de Bruin's page:
    http://www.rondebruin.nl/calendar.htm

    Ron has some instructions on how to use it on that same page.
    I am sorry that this is a little off topic. But does anyone have something similar but that also incorporates time?

  7. #7
    Claus Mygind
    Guest

    Re: Formatting a text box for date entry only

    Yes that would be correct. Thanks for the tip!

    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    > Yes, you did have that userform note. I missed it.
    >
    > You will have to move Bob's code to a different procedure, though, right?
    >
    > Maybe the "TextBox1_Exit" procedure?
    >
    >
    >
    > Claus Mygind wrote:
    > >
    > > Dave
    > > Thanks for the input. I did specify that the text box was on a user

    form.
    > > But I like the information with the calander picker. I am going to see

    if I
    > > can work that in. Thanks for the response. For a quick fix I may use

    Bob's
    > > example as I see I can plug that in fairly easily.
    > >
    > > Claus
    > >
    > > "Dave Peterson" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > The subject says a textbox--but it doesn't give a hint about where

    that
    > > textbox
    > > > is--on a worksheet or on a userform.
    > > >
    > > > And if it's on a worksheet, it doesn't say if it's a textbox from the

    > > drawing
    > > > toolbar or from the Control toolbox toolbar.
    > > >
    > > > ==
    > > > To the OP, you may want to look at using a calendar control.
    > > >
    > > > There's a link to a free calendar control at the bottom of Ron de

    Bruin's
    > > page:
    > > > http://www.rondebruin.nl/calendar.htm
    > > >
    > > > Ron has some instructions on how to use it on that same page.
    > > >
    > > >
    > > >
    > > > Bob Phillips wrote:
    > > > >
    > > > > Not really, but you can ensure it is a date, like so
    > > > >
    > > > > Option Explicit
    > > > >
    > > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > > Dim fValid As Boolean
    > > > >
    > > > > fValid = False
    > > > > On Error GoTo ws_exit
    > > > > Application.EnableEvents = False
    > > > > If Not Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
    > > > > With Target
    > > > > If IsNumeric(.Value) Then
    > > > > If IsDate(.Value) Then
    > > > > If Year(.Value) >= 1970 And Year(.Value) <= 2999

    > > Then
    > > > > fValid = True
    > > > > End If
    > > > > End If
    > > > > End If
    > > > > If Not fValid Then
    > > > > MsgBox "Invalid value"
    > > > > .Value = ""
    > > > > End If
    > > > > End With
    > > > > End If
    > > > >
    > > > > ws_exit:
    > > > > Application.EnableEvents = True
    > > > > End Sub
    > > > >
    > > > > 'This is worksheet event code, which means that it needs to be
    > > > > 'placed in the appropriate worksheet code module, not a standard
    > > > > 'code module. To do this, right-click on the sheet tab, select
    > > > > 'the View Code option from the menu, and paste the code in.
    > > > >
    > > > > You can tune the limits.
    > > > >
    > > > > --
    > > > > HTH
    > > > >
    > > > > Bob Phillips
    > > > >
    > > > > "Claus Mygind" <[email protected]> wrote in message
    > > > > news:%[email protected]...
    > > > > > Is there a way to format a text box on a user form to only allow

    date
    > > > > > entries ie: mm/dd/yy or mm/dd/yyyy?
    > > > > >
    > > > > >
    > > >
    > > > --
    > > >
    > > > Dave Peterson

    >
    > --
    >
    > Dave Peterson




+ 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