Results 1 to 10 of 10

Adding up textbox values in multipage - page 1 is fine, page 2 stops

Threaded View

  1. #1
    Registered User
    Join Date
    02-17-2020
    Location
    Germany
    MS-Off Ver
    2019
    Posts
    28

    Adding up textbox values in multipage - page 1 is fine, page 2 stops

    Hi there,

    in a userform multipage, I need to create multiple textboxes and a label which sums them up in a "live" manner which means that as soon as a value is entered/changed in a textbox, the label value changes. This may happen on mutiple pages but depending on inputs, some multipage pages may not have these functionalities. I read some similar issues in this forum and using class modules, I managed to do that... almost. The problem is: If only one page has textboxes and the label, it works perfectly. As soon as a second page has the same functionality, it stops working. So my first thought went to the textbox naming but all textboxes have unique names and are called by them so I cannot spot the mistake. I hope you can help me with that.

    Creation of textboxes (all within a for loop which goes through the multipage pages using i):
    Dim weightingsCriteriaTextbox As Control
    Set weightingsCriteriaTextbox = MultiPage1.Pages(i + 1).Controls.Add("Forms.TextBox.1", "weighting_criterion_" & decisionFactor(i, j), True)
    Creation of sum label:
    Dim sumOfCriteria As Control
    Set sumOfCriteria = MultiPage1.Pages(i + 1).Controls.Add("Forms.Label.1", "sumOfCriteria" & i, True)
    Class module stuff (from this forum. I don't fully understand it but it does the job):
    Set tbCollectionCriteria = New Collection
    For Each ctrl In Me.MultiPage1.Pages(i + 1).Controls
      If TypeOf ctrl Is MSForms.TextBox Then
        Set objCrit = New clsTextBoxCriteria
        Set objCrit.Control = ctrl
        tbCollectionCriteria.Add objCrit
      End If
    Next ctrl
    Set objCrit = Nothing
    Within the class module:
    Private WithEvents MyTextBox As MSForms.TextBox
    Public Property Set Control(tb As MSForms.TextBox)
        Set MyTextBox = tb
    End Property
    
    Private Sub MyTextBox_Change()
        AutoCalc
    End Sub
    AutoCalc:
    For i = 0 To numberOfFactors - 1
      For j = 1 To numberOfCriteria(i)
        Weightings(i, j) = CInt(Form_Weighting.Controls("weighting_criterion_" & decisionFactor(i, j)).value)
        sum = sum + Weightings(i, j)
      Next j
            
      For Each ctrl In Form_Weighting.MultiPage1.Pages(i).Controls
        If Left(ctrl.Name, 13) = "sumOfCriteria" Then
          ctrl.Caption = "Total: " & sum
        End If
      Next ctrl
    Next i
    I assume this is the essential code. Let me know if you need more. If required, I could try to attach a minimal example workbook but as the actual work is confidential, this would need a quite a bit of rework so I thought maybe this code is already enough to solve the issue.

    Any help is much appreciated!
    Last edited by Menohavename; 03-17-2020 at 01:57 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Multipage Control - Page Contents not changing with coded page change
    By Jenn68 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-26-2022, 08:20 PM
  2. Replies: 6
    Last Post: 06-05-2018, 04:53 PM
  3. Adding a page to Multipage with code
    By AdiK in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-13-2017, 07:11 AM
  4. Replies: 4
    Last Post: 08-28-2014, 02:23 AM
  5. Autofill TextBox on each page of Multipage Userform
    By kimmcms in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-20-2013, 06:45 PM
  6. Hiding Content of specific Multipage page but not the page tab
    By kuraitori in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2010, 03:42 AM
  7. Adding controls to each page in a multipage form
    By michael fuller in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-13-2006, 05:50 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