How can I combine data elements into a single data object

StephenGKorea

New Member
Joined
Feb 27, 2005
Messages
28
I am building a rather good size userform that now I am putting in all the bells and whistles now (i.e. idiot proof the form now)

It is getting really lengthy code-wise because I want certain things to be enabled and disabled on the form as they click on certain options.
I know I can hard code the lines but so I am trying to come up with some coding elements where I will not have to add 20+ lines of code for everytime I want to add a new feature.

Here is one of the functions that I have, There is going to be several of these:

Private Sub chkMore2_Click()
If chkMore2 = True Then
cboProtocol2.BackStyle = fmBackStyleOpaque
cboApplication2.BackStyle = fmBackStyleOpaque
txtLowPort2.BackStyle = fmBackStyleOpaque
txtHighPort2.BackStyle = fmBackStyleOpaque
txtAIS2.BackStyle = fmBackStyleOpaque
txtVer2.BackStyle = fmBackStyleOpaque
optDynamicYes2.BackStyle = fmBackStyleOpaque
optDynamicNo2.BackStyle = fmBackStyleOpaque
chkMore3.Enabled = True
cboProtocol2.Enabled = True
cboApplication2.Enabled = True
txtLowPort2.Enabled = True
txtHighPort2.Enabled = True
txtAIS2.Enabled = True
txtVer2.Enabled = True
optDynamicYes2.Enabled = True
optDynamicNo2.Enabled = True
End If

So If I click chkMore2 ... all of the 2nd elements will be editable. If I click chkMore3 ... then all of the 3rd elements will be editable, etc. etc.

So I tried to play with this code example:

Private Sub CheckBox1_Click()
If CheckBox1 = True Then
Call Changeit(1, "yes")
Else
Call Changeit(1, "no")
End If
End Sub

Function Changeit(box As Integer, yn As String) As String
With Application.WorksheetFunction
If yn = "yes" Then
.concatenate("TextBox", box).Value = "yes"
Else
.concatenate("TextBox", box).Value = "no"
End If
End With
End Function


Excel 2007 does not like the .concatenate element, I have tried other ways, but I can not seem to get anything to work or I wouldnt be asking, huh? :)

TIA
Stephen
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
What about something like this

Sub checkControl()
Dim i As Long
For i = 1 To 32
' Code goes here
MsgBox Me.Controls("TextBox" & i).Text
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,484
Members
452,917
Latest member
MrsMSalt

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