+ Reply to Thread
Results 1 to 3 of 3

Userform Textbox - Capturing Mouse Click

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    Surrey, BC
    MS-Off Ver
    Excel 2016
    Posts
    84

    Userform Textbox - Capturing Mouse Click

    Hi there again!
    I have a userform with many textboxes (105) that currently when I enter one or two numbers and press "Enter" a generic procedure is run via the "KeyDown" event, manipulating the numbers entered. The problem I am having and am not sure how to fix is; if the user mouse clicks on another textbox without hitting "Enter", the focus changes to the new textbox without firing the "KeyDown" event from the previous textbox. Currently I am using a "KeyDown" event only to trigger my procedure.

    How can I make better use of the events by picking up both the "EnterDown" and the left mouse click.

    Here is a sample of my code:

    Please Login or Register  to view this content.

    Thanks Craig

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Userform Textbox - Capturing Mouse Click

    Hi.

    Firstly with that many text boxes I would use a subroutine to handle my text boxes

    I then use a macro to create my textbox events in excel and copy paste into VBA.


    Secondly I would do the same for the mouse down and textbox enter events.

    Start of by declaring T as a global variable.

    this is the sort of code that I use:-

    Please Login or Register  to view this content.
    ConEnter, ConChange and ConExit are my three subroutines and they work for all my text boxes.

    So clicking t is your existing text box, clicking on textbox2 will trigger the textbox1 exit sub ie ConExit and then run the textbox2 entry sub ie ConEnter.

    My Macro for creating the textbox vb code is quite simple.

    bear with me and I will modify it to create your 105 x 5 macros.


    Clicking on the button in the attached file will create 525 macros for you.

    Then all you need is 3 subroutines.



    Now that you have your textbox events trapped all you you to do is write the subroutines.


    Please Login or Register  to view this content.
    Modify hange_SpecialHours and next_SPtextbox to use T as the textbox number.

    you can use something like

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 04-07-2015 at 01:47 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    10-18-2012
    Location
    Surrey, BC
    MS-Off Ver
    Excel 2016
    Posts
    84

    Re: Userform Textbox - Capturing Mouse Click

    I ended up having trouble with the event firing order. The mouse click fired on first click and I ended up with strange results. I decided to make some changes and used comboboxes instead of textboxes which made my code run much more efficient. This way my code always fires correctly and I can force the user to choose the items available.

    I did love the macro for creating the events codes... could have used that 10 years ago... all the editing I have done in the past would have saved me lots of time.

    Craig

+ 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. Get UserForm checkbox caption and pass to another UserForm on click or mouse down
    By tulsaguy71 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-08-2013, 11:07 AM
  2. Userform textbox needs to show data, without having to click
    By scott marks in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-31-2013, 09:17 AM
  3. Replies: 0
    Last Post: 03-06-2013, 12:52 PM
  4. Userform w/textbox search a table for a value on click
    By trader07 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 03-30-2011, 03:45 AM
  5. Right-click in userform textbox.
    By ilovelagar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-01-2009, 03:08 PM

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