Here is the code:
Public Sub F5ScreenAdjust_To_Date_Amts_For_Entry_To_DB()
Dim LenOfName As Long
Dim cntr As Control
Dim MTDTextBox As Control
Dim TxtBoxName As String
'Loop thru controls on frmF5AddEmpEarn to find text boxes.
For Each cntr In frmF5AddEmpEarn.Controls
If TypeOf cntr Is TextBox Then 'cntr is short for control.
Select Case Right(cntr.Name, 3) 'Look to see if txt box is for Quarter or Year.
Case "QTD"
LenOfName = Len(cntr.Name) - 3
TxtBoxName = (Left(cntr.Name, LenOfName) & "MTD")
Set MTDTextBox = frmF5AddEmpEarn!TxtBoxName
cntr.Text = cntr.Text - MTDTextBox
Case "YTD"
End Select
End If
Next
End Sub
I am looping thru all the text boxes on a form and trying to subtract one from another. All the text in the text boxes is numeric.I want TxtBoxName to be the name of a txt box on the form so that I can use it's text property.
tnfaxpay,
Tom
Public Sub F5ScreenAdjust_To_Date_Amts_For_Entry_To_DB()
Dim LenOfName As Long
Dim cntr As Control
Dim MTDTextBox As Control
Dim TxtBoxName As String
'Loop thru controls on frmF5AddEmpEarn to find text boxes.
For Each cntr In frmF5AddEmpEarn.Controls
If TypeOf cntr Is TextBox Then 'cntr is short for control.
Select Case Right(cntr.Name, 3) 'Look to see if txt box is for Quarter or Year.
Case "QTD"
LenOfName = Len(cntr.Name) - 3
TxtBoxName = (Left(cntr.Name, LenOfName) & "MTD")
Set MTDTextBox = frmF5AddEmpEarn!TxtBoxName
cntr.Text = cntr.Text - MTDTextBox
Case "YTD"
End Select
End If
Next
End Sub
I am looping thru all the text boxes on a form and trying to subtract one from another. All the text in the text boxes is numeric.I want TxtBoxName to be the name of a txt box on the form so that I can use it's text property.
tnfaxpay,
Tom