Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to name a txt box object from a string & use in loop. 1

Status
Not open for further replies.

faxpay

Programmer
Nov 30, 2004
119
US
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
 
Try changing the line

Code:
Set MTDTextBox = frmF5AddEmpEarn!TxtBoxName

to

Code:
Set MTDTextBox = frmF5AddEmpEarn.Controls.Item(TxtBoxName)



Heaven doesn't want me, and Hell's afraid I'll take over!
 
Unscruffed,

That did it. Works Great.
I thank you much.

faxpay,
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top