I have this small amount of code to gather values from a form's text boxes, perform a calculation, then place the results into other text boxes. It works fine. The example below is for one section. I will have up to 5 sections to perform this on. Instead of creating 5 command buttons and 5 sub routines, I would like create a loop to run through all five sections using one cmd button. Every text box name that I'm using ends in the section number it represents. S1 would be section 1, S2 would be section 2, etc. Everywhere there is an S1, I would like it increment to S2, S3, S4, and S5 to perform the calculation. I've tried a few things to get the text box name to change but have had no success. That's why I'm here. Can't really create the loop until I can figure out how get the right data. If I'm not able to do this or there is a different way to approach this then let me know. Thanks ahead of time.
Private Sub cmdSECTION1_Click()
On Error GoTo Err_ cmdSECTION1_Click
'SECTION 1
VALUE1 = Me.txtVALUE1
If optATTACHED = -1 Then
LENGTH = Me.txtLENGTHS1 - 4.921
Else
LENGTH = Me.txtLENGTHS1
End If
MCL = Me.cboTYPES1.Column(2)
MCLS = MCL * LENGTH
LAF = TRANSLOSS(MCLS, VALUE1, LENGTH)
TERMS = ((Me.cboCONS1 - 1) + (Me.cboPOLYS1 - 1) + (Me.cboTHRUS1 - 1)) * 0.03
Me.txtLOSSS1 = LAF + TERMS
Me.txtINITCLS1 = LAF + TERMS + 0.5
Exit_ cmdSECTION1_Click:
Exit Sub
Err_ cmdSECTION1_Click:
MsgBox Err.Description
Resume Exit_ cmdSECTION1_Click
End Sub
Private Sub cmdSECTION1_Click()
On Error GoTo Err_ cmdSECTION1_Click
'SECTION 1
VALUE1 = Me.txtVALUE1
If optATTACHED = -1 Then
LENGTH = Me.txtLENGTHS1 - 4.921
Else
LENGTH = Me.txtLENGTHS1
End If
MCL = Me.cboTYPES1.Column(2)
MCLS = MCL * LENGTH
LAF = TRANSLOSS(MCLS, VALUE1, LENGTH)
TERMS = ((Me.cboCONS1 - 1) + (Me.cboPOLYS1 - 1) + (Me.cboTHRUS1 - 1)) * 0.03
Me.txtLOSSS1 = LAF + TERMS
Me.txtINITCLS1 = LAF + TERMS + 0.5
Exit_ cmdSECTION1_Click:
Exit Sub
Err_ cmdSECTION1_Click:
MsgBox Err.Description
Resume Exit_ cmdSECTION1_Click
End Sub