+ Reply to Thread
Results 1 to 6 of 6

On Button Press Send Value to Selected/Active TextBox?

  1. #1
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    On Button Press Send Value to Selected/Active TextBox?

    Just an experiment / learning.

    I have several TextBoxes on the screen (in a userform). I want to be able to click in one and then click Button and then the Button would send value to the TextBox that is active.

    Very simple but yes, I am that new. I know how to pass the variable to a specific Textbox just not the focused one.

    Please Login or Register  to view this content.
    Thanks in advance!

    Is this correct?

    Please Login or Register  to view this content.
    Last edited by NewYears1978; 02-21-2015 at 07:35 PM.

  2. #2
    Registered User
    Join Date
    04-14-2010
    Location
    NZ
    MS-Off Ver
    2007,2010
    Posts
    86

    Re: On Button Press Send Value to Selected/Active TextBox?

    something like this?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: On Button Press Send Value to Selected/Active TextBox?

    Both seem to work, thanks!

    Actually, earlier I tried

    Please Login or Register  to view this content.
    And it was simple and worked, but now that is throwing an error Runtime 438, object doesn't support this property or method.

    Trying your method Deamo but I don't know how to implement it.

    Edit:
    Figure it out, thanks Deamo, am curious why my other method worked, then didn't later??

    So, This works great, but I have 50 buttons that I have to duplicate the below code

    Please Login or Register  to view this content.
    Is there a way to condense that without having to repeat the above 50 times (I have 50 buttons that return color values so for each color value I have to duplicate the above)

    They are all buttons named "Color1" "Color2" "Color50" etc but there are some numbers missing so it is not 1-50. The value to be given matches the number on the button, so Color50 would send value 50.

    Thanks again
    Last edited by NewYears1978; 02-22-2015 at 12:26 AM.

  4. #4
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: On Button Press Send Value to Selected/Active TextBox?

    I also ran into another problem.

    When I first make these textboxes visible, the focus is in the first one by default. If I click the button as right away I get a strange error, I have to click the mouse into the box first (which makes sense I supposed since your code uses mouse functions)

    How can I make it work when the box is active but I have not clicked with the mouse?

  5. #5
    Registered User
    Join Date
    04-14-2010
    Location
    NZ
    MS-Off Ver
    2007,2010
    Posts
    86

    Re: On Button Press Send Value to Selected/Active TextBox?

    I noticed that too.. how to pick up which control has the focus prior to a mouse click (aside from using the activate event of the form) is eluding me.

    Norrie mentioned in this thread about using a class to handle multiple combobox change events, which may work here too - I have no experience with this, yet.

    Edit: turns out you can use the Enter event of the textboxes, as that's triggered when the form is loaded
    Last edited by Deamo; 02-22-2015 at 04:44 AM.

  6. #6
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: On Button Press Send Value to Selected/Active TextBox?

    Quote Originally Posted by Deamo View Post
    I noticed that too.. how to pick up which control has the focus prior to a mouse click (aside from using the activate event of the form) is eluding me.

    Norrie mentioned in this thread about using a class to handle multiple combobox change events, which may work here too - I have no experience with this, yet.

    Edit: turns out you can use the Enter event of the textboxes, as that's triggered when the form is loaded
    I tried that just now but getting the same error, must have implemented it wrong?

    Oh I got it, I had tested the one I didn't change

    Please Login or Register  to view this content.
    Works perfect, thanks!

    Now I need to streamline this some how so I don't have to post the code 50 times.

    Please Login or Register  to view this content.
    That's for 1 button and there are approximately 5



    Another question about this same thing, when clicking the button the focus is lost (no focus anywhere on form) and I have to Tab back into it. Anyway to keep focus on the box (so that I can have it go to the next box)
    Unsure why focus is being lost.
    Last edited by NewYears1978; 02-22-2015 at 01:18 PM.

+ 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. Press submit button and send data to Access
    By Charonix in forum Access Tables & Databases
    Replies: 1
    Last Post: 01-08-2014, 02:34 PM
  2. [SOLVED] Select varying quantity of rows, press macro button to send selection to new workbook
    By tv69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2013, 10:09 AM
  3. [SOLVED] Press a button to SEND data from one worksheet to another based on conditions set by user
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-21-2012, 10:30 AM
  4. Userform: Pass textbox values to another textbox on button press
    By adjustermn in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2010, 11:19 PM
  5. Replies: 17
    Last Post: 05-19-2009, 11:34 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