+ Reply to Thread
Results 1 to 5 of 5

LostFocus event for TextBox - how to make it work

  1. #1
    Registered User
    Join Date
    11-30-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    54

    LostFocus event for TextBox - how to make it work

    Hi,
    I am not an expert in VBA so I am struggling to make my form work like I want.

    I would like to have a textbox on a form. In this textbox user will enter weight of item he wishes to add to database so I want to format text in this box as " #.0 kg".

    I wanted to use LostFocus event but I am unable to make it work. It seems no to occur, my code has no effect.

    I am attaching my file. Please help me to understand what is happening.

    Cris
    Attached Files Attached Files

  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,258

    Re: LostFocus event for TextBox - how to make it work

    Hello kmeld,

    Welcome to the Forum!

    On a UserForm, the controls have an Enter and Exit event. This is similar to GetFocus and LostFocus. You tried to add an event that the control did not support. That is why your code didn't work.

    Copy this macro to your UserForm. This will format the text box entry once the input is shifted to the next control.

    Please Login or Register  to view this content.
    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
    11-30-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    54

    Re: LostFocus event for TextBox - how to make it work

    Hi.
    Thanks, it helped.

    I earlier managed to get the same result with:
    Private Sub Text_ilosc_AfterUpdate()

    then I tried:
    Private Sub TextBox1_Exit()
    and it didn't work

    however with:
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    it works.

    Could you explain me the difference between () and (ByVal Cancel As MSForms.ReturnBoolean) in case of exit event.

    I was looking for some list of available events for text boxes and other objects but did not find anything what I could really use. Either I was not experienced enough to understand fully or informations ware so general that it really meant nothing. (like for example this one)
    http://msdn.microsoft.com/en-us/libr...ice.15%29.aspx

    Regards,
    Cris

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

    Re: LostFocus event for TextBox - how to make it work

    Hello kmeld,

    The empty parentheses () indicates the procedure does not take any arguments. Whether a procedure takes arguments or not depends on how the procedure was written. In the case of the TextBox events, you can not change the arguments.

    The link you cited will provide with more information. On the left side of the page above "Objects", you will see "Reference". Click the triangle to display more information. You will see: Collections, Dialog Boxes, Events, Examples, Methods, and Properties. Click Events to see what is available to you.

  5. #5
    Registered User
    Join Date
    11-30-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    54

    Re: LostFocus event for TextBox - how to make it work

    Hi,

    thanks,
    I was looking for this.
    This on-line help browser works a bit strange and I am having some difficulty using it.

    Cris

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to make my code work as an event macro
    By strud in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-13-2013, 11:32 AM
  2. creating a custom class event for worksheet textbox lostfocus
    By Willardio in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-27-2013, 02:00 AM
  3. how to make a lostfocus event?
    By Willardio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2013, 12:25 PM
  4. lostfocus event: if text box height exceeds n points, call sub
    By Willardio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2013, 09:38 AM
  5. Userform textbox event that fires after I exit the textbox
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-04-2010, 08:08 AM

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