Getting at both values of a Combobox using the name property

rrobnett

New Member
Joined
Jan 5, 2018
Messages
1
I have a class file that stores each control for a series of userform comboboxes and textboxes


Class module: materialField


Code:
Option Explicit


Private fieldName As String
Private fieldValue As Variant
Private fieldValue2 As String


Property Get Name() As String
    Name = fieldName
End Property


Property Get Value() As Variant
    Value = fieldValue
End Property


Property Get value2() As String
    value2 = fieldValue2
End Property


Property Let Name(str As String)
    fieldName = str
End Property


Property Let Value(val As Variant)
    fieldValue = val
End Property


Property Let value2(str As String)
    fieldValue2 = str
End Property


I am using a for loop to put the information into each instance of the class as below.


Code:
Option Explicit


Private mats(1 To 10, 1 To 3) As MaterialField


Private Sub FillTblArray()
    Dim i As Integer
    Dim j As Integer
    Dim str As String
        
    For i = 1 To 10
        For j = 1 To 3
            Set mats(i, j) = New MaterialField
            
            If (j = 1) Then
                str = "CB" & i
                mats(i, j).Name = str
                                
                mats(i, j).Value = Me.Controls(str).Value
                mats(i, j).value2 = Me.Controls(str).Column(1).Value
            Else
                str = "TB" & i & (j - 1)
                mats(i, j).Name = str
                mats(i, j).Value = Me.Controls(str).Value
            End If
        Next j
    Next i
End Sub


Code:
mats(i, j).Value = Me.Controls(str).Value
stores the first column of the combobox
Code:
mats(i, j).value2 = Me.Controls(str).Column(1).Value
throws an error


I need to get at this value and store it using only the name or type property. I know I am missing something please help me figure it out. Thank you in advance.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Welcome to the Board

Code:
Private Sub FillTblArray()
Dim i As Integer, j As Integer, str$, x
For i = 1 To 2
    For j = 1 To 2
        Set mats(i, j) = New Classe1
        If (j = 1) Then
            str = "CB" & i
            mats(i, j).Name = str
            mats(i, j).Value = Me.Controls(str).Value
            MsgBox Me.Controls(str).Column(0) & vbLf & Me.Controls(str).Column(1)
            mats(i, j).value2 = Me.Controls(str).Column(1)
        Else
            str = "TB" & i & (j - 1)
            mats(i, j).Name = str
            mats(i, j).Value = Me.Controls(str).Value
        End If
    Next
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,173
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top