+ Reply to Thread
Results 1 to 5 of 5

Form Issue in VBA

  1. #1
    Registered User
    Join Date
    09-07-2005
    Location
    Scotland
    Posts
    7

    Unhappy Form Issue in VBA


    Afternoon folks,

    Could anyone help here? when i create a form that when you type in the time it sends that data to the controlsource cell - no probs there but the form changes to a decimal number eg 09:00 when typed changes to 0.375 on the form, i would like this to stay as 09:00 (or whatever the value is when typed in 24hr format.

    oops - im using excel 2000 at my work to do this.

    Any Ideas?

  2. #2
    Nigel
    Guest

    Re: Form Issue in VBA

    Put this code behind the form. As you exit the TextBox1 with the time
    entered, the value is formatted to a time.
    I also include an enter event to ensure the value in the control source is
    properly formatted as the form opens.

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    TextBox1.Value = Format(TextBox1.Value, "hh:mm")
    End Sub

    Private Sub TextBox1_Enter()
    TextBox1.Value = Format(TextBox1.Value, "hh:mm")
    End Sub


    --
    Cheers
    Nigel



    "cdu311" <[email protected]> wrote in
    message news:[email protected]...
    >
    >
    > Afternoon folks,
    >
    > Could anyone help here? when i create a form that when you type in the
    > time it sends that data to the controlsource cell - no probs there but
    > the form changes to a decimal number eg 09:00 when typed changes to
    > 0.375 on the form, i would like this to stay as 09:00 (or whatever the
    > value is when typed in 24hr format.
    >
    > oops - im using excel 2000 at my work to do this.
    >
    > Any Ideas?
    >
    >
    > --
    > cdu311
    > ------------------------------------------------------------------------
    > cdu311's Profile:

    http://www.excelforum.com/member.php...o&userid=27051
    > View this thread: http://www.excelforum.com/showthread...hreadid=469163
    >




  3. #3
    Registered User
    Join Date
    09-07-2005
    Location
    Scotland
    Posts
    7

    Talking Peaches

    Hi Nigel,

    Thanks for that - works a charm now.

    Regards

    Lee Elliot

  4. #4
    Registered User
    Join Date
    09-07-2005
    Location
    Scotland
    Posts
    7

    Question Eh?



    i tried to impliment the same type of code for a combo box
    but it no work?!

    is there anything different required there?

    Private Sub Combobox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    ComboBox2.Value = Format(ComboBox2.Value, "hh:mm")
    End Sub

    Private Sub Combobox2_Enter()
    ComboBox2.Value = Format(ComboBox2.Value, "hh:mm")
    End Sub


    sorry to be a pain

  5. #5
    Registered User
    Join Date
    09-07-2005
    Location
    Scotland
    Posts
    7

    Smile No Matter



    Got it. Sorry again.

+ 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