Results 1 to 17 of 17

Trying to reuse code to access multiple Textboxes

Threaded View

dentler Trying to reuse code to... 10-07-2021, 06:37 PM
6StringJazzer Re: Trying to reuse code to... 10-07-2021, 09:27 PM
dentler Re: Trying to reuse code to... 10-07-2021, 09:31 PM
Akuini Re: Trying to reuse code to... 10-07-2021, 10:41 PM
dentler Re: Trying to reuse code to... 10-07-2021, 10:48 PM
Akuini Re: Trying to reuse code to... 10-07-2021, 10:54 PM
Artik Re: Trying to reuse code to... 10-08-2021, 05:36 AM
jindon Re: Trying to reuse code to... 10-08-2021, 09:57 AM
dentler Re: Trying to reuse code to... 10-08-2021, 01:16 PM
Akuini Re: Trying to reuse code to... 10-08-2021, 07:54 PM
dentler Re: Trying to reuse code to... 10-08-2021, 08:05 PM
dentler Re: Trying to reuse code to... 10-09-2021, 12:37 AM
dentler Re: Trying to reuse code to... 10-09-2021, 12:38 AM
Akuini Re: Trying to reuse code to... 10-09-2021, 12:52 AM
jindon Re: Trying to reuse code to... 10-08-2021, 09:53 PM
dentler Re: Trying to reuse code to... 10-10-2021, 12:27 PM
jindon Re: Trying to reuse code to... 10-10-2021, 09:26 PM
  1. #1
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    141

    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.

      
    If IsNumeric(Assets.TextBox31.Value) Then
                lDecPoint = InStr(Assets.TextBox31.Value, ".")
                If lDecPoint > 0 And Len(Assets.TextBox31.Value) - lDecPoint >= 2 Then
                    Assets.TextBox31.Value = Left(Assets.TextBox31.Value, lDecPoint + 2)
                End If
            End If
    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:
      
    Sub convertTextbox()
    Dim newTextBoxName As String
    MsgBox TbNum
    newTextBoxName = "Assets.TextBox" & TbNum
    MsgBox newTextBoxName
            
            'If IsNumeric(newTextBoxName.Value) Then
                'lDecPoint = InStr(newTextBoxName.Value, ".")
                'If lDecPoint > 0 And Len(newTextBoxName.Value) - lDecPoint >= 2 Then
                    'newTextBoxName.Value = Left(newTextBoxName.Value, lDecPoint + 2)
                'End If
            'End If
            
            If IsNumeric(Assets.TextBox31.Value) Then
                lDecPoint = InStr(Assets.TextBox31.Value, ".")
                If lDecPoint > 0 And Len(Assets.TextBox31.Value) - lDecPoint >= 2 Then
                    Assets.TextBox31.Value = Left(Assets.TextBox31.Value, lDecPoint + 2)
                End If
            End If
    End Sub
    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

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