+ Reply to Thread
Results 1 to 6 of 6

Textbox Exit Event Cant not be trigger

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2011
    Location
    Richmond, BC
    MS-Off Ver
    Excel 2007
    Posts
    69

    Textbox Exit Event Cant not be trigger

    Hi,

    I have three text boxes on my worksheet.
    They are for Start Time, End Time and Time Half Way between the start and end time.
    I want the third text box to calculate the half time when both start time and end time are entered.

    I tried the code below, but it won't tiger. Please help.
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        Dim startTime, endTime As Double
        
        startTime = TimeValue(TextBox1.Value)
        endTime = TimeValue(TextBox3.Value)
        
        
        TextBox4.Value = Left((endTime - startTime), 4)
        
    End Sub
    Thank you very much,

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Textbox Exit Event Cant not be triger

    Hello stewegg,

    This should work...
        TextBox4.Value = Format((endTime - startTime)/2, "hh:mm:ss")
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-03-2011
    Location
    Richmond, BC
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Textbox Exit Event Cant not be triger

    Hi Leith Ross,

    Thank you for your help.
    It only works when I click "run" in VBA.
    It doesn't run automatically.
    Am I missing something?
    Also, I can not tab through or use enter to go to the next text box for some reason...

    Thank you very much

  4. #4
    Valued Forum Contributor
    Join Date
    03-14-2012
    Location
    Arizona USA
    MS-Off Ver
    Excel 2000/2007
    Posts
    408

    Re: Textbox Exit Event Cant not be triger

    If the end time is in textbox3, then use TextBox3_AfterUpdate event.

    It tested this with good results

    Private Sub TextBox2_AfterUpdate()
        
        startTime = TimeValue(CDate(TextBox1.Value))
        endTime = TimeValue(CDate(TextBox2.Value))
        
        TextBox3.Value = Format(CDate(startTime + (endTime - startTime) / 2), "hh:mm:ss")
        
    End Sub
    TextBox1 has the StartTime
    TextBox2 has the EndTime
    TextBox3 has the MiddleTime

  5. #5
    Registered User
    Join Date
    02-03-2011
    Location
    Richmond, BC
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Textbox Exit Event Cant not be triger

    Hi Dennis,

    It only works when I click "run" in VBA.
    It doesn't run automatically.
    Am I missing something?


    Thank you very much

  6. #6
    Registered User
    Join Date
    02-03-2011
    Location
    Richmond, BC
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Textbox Exit Event Cant not be trigger

    Anyone? Help?

+ 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