Dynamic textbox question

L

Larry

Is there a way to set a textbox equal to a variable? For instance, can I do
something like this:

strTextbox = "txtName" 'the name of an actual textbox on a form.
set objTextbox = strTextbox

OR This:

set objTextbox = "txtName" & intCtr

where this would let me reference one of many similarly named text boxes
(i.e. txtName1, txtName2, etc). I've never been able to figure a way to do
this.

Thanks!
 
M

Mike Labosh

Is there a way to set a textbox equal to a variable? For instance, can I
do
something like this:

strTextbox = "txtName" 'the name of an actual textbox on a form.
set objTextbox = strTextbox

OR This:

set objTextbox = "txtName" & intCtr

This should work (untested):

Dim strTextBox As String
Dim objTextBox As Control

strTextBox = "txtName"

Set objTextBox = Me.Controls(strTextBox)
 
Top