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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting a string to a text box name

Status
Not open for further replies.

nickjar2

Programmer
Jun 20, 2001
778
US
I have some code that loops through the controls on a form. If a check box is checked then i want the corresponding text box to be made required.

eg.

blah blah
if cControl.controlType = acCheckBox then
if cControl.value = -1 then
sTextBox = "txt" & Right$(s, Len(s) - 3)
else
goto ignore
end if
else
goto ignore
end if

ignore:

I now have, say, sTextBox = txtMechanical. How can i convert this string value to a control value so I can refer to it like:
if sTextBox.enabled then...

If this does not make sense please let me know. I have spent ages today trying all sorts of things.

Please help,

Nick
 
how about after initializing sTextBox = "text"
then control.name = sTextBox.text
 
Thanks, but would i easily say, right i have a string = txtMechanical, now check the txtMechanical field and see if it is enabled? (bearing in mind i have about 8 fields)

Cheers

Nick
 
If I understand it right what you want to do, then probably adding:

ctl.value = sTextBox

if ctl.value <> &quot; &quot; Then
ctl.enabled = True
'next code what to do if txtMechanical can receive focus
else
ctl.enabled = False
end if

 
cheers,

That seems good. I will try that tomorrow and see if it works.

Thanks,

Nick
 
TT,

at this line, ctl.value = sTextBox, I get object variable not set.

Cheers,

Nick
 
Means it doesn't recognize the string. Have you declared it?

 
Cheers 4 the help Tin Tin.

I created another loop within the loop. That seems to have done the trick.

Cheers

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top