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

Substitution variables for form control names

Status
Not open for further replies.

LarryDK

Programmer
Dec 23, 1999
12
US
In MS Access I would like to reference a control using a string variable. If my form and control name was something like Forms![Form1]![Control1] and I want Control1 to be substituted in by appending an index to the word &quot;Control&quot; something like 'newname=&quot;Control&quot; & index' where index is a number and then use it like Forms![Form1]!newname.<br>
<br>
Whatever I try does not seem to work. Plase let me know what I am doing wrong.<br>
<br>

 
First of all you're are in the wrong forum But anyway.<br>
Is this what you are trying to do?<br>
You can use the ActiveControl property to refer to the control that has the focus at run time together with one of its properties or methods. The following example assigns the name of the control with the focus to the strControlName variable:<br>
<br>
Dim ctlCurrentControl As Control<br>
Dim strControlName As String<br>
Set ctlCurrentControl = Screen.ActiveControl<br>
strControlName = ctlCurrentControl.Name<br>
<br>
If no control has the focus when you use the ActiveControl property, or if all of the active form's controls are hidden or disabled, an error occurs.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top