+ Reply to Thread
Results 1 to 17 of 17

Trying to reuse code to access multiple Textboxes

  1. #1
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Question Trying to reuse code to access multiple Textboxes

    So I have created a userform called Assets which contain multiple text and combo boxes. Presently I have only been playing with Textbox31 which on the attached example is the first textbox beneath Amount. I can use the following code in each textbox for data entry, and that works great.

    Please Login or Register  to view this content.
    But I would like to reduce the code and have the code within the Textbox on the userform call a routine, that will allow it to change the name for each textbox. So I have created the following sub routine:
    Please Login or Register  to view this content.
    In the above code you will see the first If statement commented out. Since when I try to run it I get an error: Compile error: Invalid Qualifier.

    I have tried a number of different solutions and suggestion that I have found searching online, but so far none of them work.

    I would also like to make it when the user is entering numbers into the textbox that the user would not have to enter the decimal point and that each time they enter a number it would then shift it to the left. For example if the enter 90 it would show as .90, but if then enter 390, then it would show as 3.90. Presently they must enter the decimal point manually. If they do not then it does not display any decimal point, so if they entered 390 and no decimal point and hit enter, it would only show 390 in the textbox.

    I hope I have made this as clear as possible.

    See the attached workbook as an example.

    Thank you for any suggestions.
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Trying to reuse code to access multiple Textboxes

    I haven't had time to try to solve your whole problem but here is why you are getting a compile error:
    Please Login or Register  to view this content.
    newTextBoxName is a String. A String is a scalar type, not an object, and so does not have a .Value attribute.

    Also, IsNumeric on newTextBoxName in your example will always be False. I have no idea what you have in mind with that so it's hard to tell you what is correct.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Trying to reuse code to access multiple Textboxes

    I have tried some code where I attempted to declare an object and had problems as well.

  4. #4
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Trying to reuse code to access multiple Textboxes

    Why are you using so many textbox & combobox?
    How about just using 3 textbox + 2 combobox + 1 listbox + 1 button
    So it works like this:
    1. Fill some data in the 3 textbox + 2 combobox > hit the button > data will be transfered to listbox (1 row at a time)
    2. Repeat the step with different data as needed.
    3. Now you have all data in the listbox, and then you can manipulate it or send it to a sheet.

  5. #5
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Trying to reuse code to access multiple Textboxes

    This sounds like a great solution, but I am not sure how to proceed in a userform? Could you provide some example?

    Thank you

  6. #6
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Trying to reuse code to access multiple Textboxes

    Could you attach a new workbook with some data to test?
    And explain what you're trying to do in more detail.

  7. #7
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: Trying to reuse code to access multiple Textboxes

    dentler, It is true that the project will develop in a different direction, but I want to show how the current code should be written.
    You want to refer to the controls on the Assets form by their names. So:
    Please Login or Register  to view this content.
    Artik

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Trying to reuse code to access multiple Textboxes

    Quote Originally Posted by dentler View Post
    For example if the enter 90 it would show as .90, but if then enter 390, then it would show as 3.90. Presently they must enter the decimal point manually. If they do not then it does not display any decimal point, so if they entered 390 and no decimal point and hit enter, it would only show 390 in the textbox.
    1) Asset form code module
    Please Login or Register  to view this content.
    2) Insert Class module (Class1) and the code
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Trying to reuse code to access multiple Textboxes

    Let me first say thank you to everyone for your suggestions. I will attach a new WB that has incorporated those suggestions into it. The new workbook contains both the old Assets form where I have incorporated data suggested by jindon . Thanks for giving me the code that I was looking for when entering amounts.

    The WB also contains a new form called DataEntry that incorporates suggestion made by Akuini. Thanks for asking the question of why so many text and combo boxes. I added data for lists used in the comboboxes and code to save those entries to a worksheet. I believe this is what you were suggesting. If you think I can make any improvements to this, please let me know.

    Thanks again to everyone. This forum is quite wonderful and all help present and past has been greatly appreciated. I will wait a bit to mark it as solved, in case there are any other suggestions.

    Please check out the attached file with the above mentions changes.
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Trying to reuse code to access multiple Textboxes

    Ok, here's how I would do it:
    I removed Userform Assets & added a listbox in Userform DataEntry

    How it works:
    1. Fill some data in the 3 textbox + 2 combobox > hit ENTER button > data will be transfered to listbox (1 row at a time)
    2. Repeat the step with different data as needed.
    3. Now you have all data in the listbox, hit Save Data to Asset button > data from listbox will be transfered to sheet DataStore
    4. In case you entered wrong data in listbox you can delete it by double-clicking the wrong item in the listbox.

    The code:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Trying to reuse code to access multiple Textboxes

    I will check this out.. Thanks again.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Trying to reuse code to access multiple Textboxes

    If just one control for each entry then try the attached.
    Remove Class1
    From code module
    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Trying to reuse code to access multiple Textboxes

    Thanks again, I really appreciate your expertise.

  14. #14
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Trying to reuse code to access multiple Textboxes

    Now I see what you were mentioning about the list box... great ! I like it.. Thank You.

  15. #15
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Trying to reuse code to access multiple Textboxes

    Quote Originally Posted by dentler View Post
    Now I see what you were mentioning about the list box... great ! I like it.. Thank You.
    Are replying to me or jindon?
    In any case, I'm glad it works.

  16. #16
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Trying to reuse code to access multiple Textboxes

    So a couple of quick questions. I was able to incorporate your suggestions /code into my WB with a couple of minor changes. Initially it failed with mismatch errors on the three lines in the initialize routine that contains the filters. I simply commented those out and it seems to work find without any issues that I have been able to see or determine.

    So my questions are, what version of office do you use to develop your code in. I use office 2019, and from what I have read, the filters are available in office 365 but not 2019, although they are available in the just released version of Office 2021. The sample WB you provided works great if I run in in Office 2019, but once I transpose the form and code into my WB that is when I get mismatch errs relating to the code containing filters.

    If you are running Office 2019 or a prior version, have you added some library or something else for filters to work? Like I said after commenting those lines out it still seems to work as intended, but just wanted to know what version you develop in?

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Trying to reuse code to access multiple Textboxes

    Filter function I used is a native vba function available from xl2003(not sure), not the worksheet function, so it is not the version problem.
    It errors when the named range has only one cell or contains error value.

    I used Filter function because your named range has empty cell(s).
    Change Initialize code to
    Please Login or Register  to view this content.

+ 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] Access Search By Combobox/Textboxes Choices
    By stfeliciasredpanda in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2020, 12:52 PM
  2. [SOLVED] Need help with Excel Query to reuse code for different months.
    By dentler in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2020, 11:47 AM
  3. date format code for multiple userform textboxes on form initialize
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2017, 05:30 AM
  4. Replies: 0
    Last Post: 02-04-2015, 03:46 PM
  5. [SOLVED] Code in userform to be flexible and work with multiple textboxes
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 01-21-2015, 11:04 AM
  6. Code Reuse - Logging Actions When a Cell Changes -2
    By webbug08 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-02-2009, 04:35 PM
  7. Code Reuse - Logging Actions When a Cell Changes
    By webbug08 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-02-2009, 06:23 AM

Tags for this Thread

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