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

Rename controls 1

Status
Not open for further replies.

takeover

Programmer
Jul 9, 2003
52
US
Hi,

Can I rename controls in VBA. I have a form with about 200 text boxes. I need to rename them all.

takeover
 
Dim ctl As Control
Dim frm As Form, x As Integer
Set frm = Forms!frmName

For Each ctl In frm.Controls
x= x + 1
If (ctl.ControlType = acTextBox) Then
ctl.Name = "txt" & x
End If
Next

Hope this helps, good Luck!
 
Hopefully NO code referencing this control ...
 
Hi,

The code doesn't work. It says "To set this property, open the form or report in design view.

takeover
 
In a separate module....

Dim ctl as Control
DoCmd.OpenForm "FormName", acDesign, , , , acHidden
For each ctl in Forms!FormName
Select Case acControlType
Case Is = acTextBox:
ctl.Name = "txt" & ctl.Name
Case Is = acComboBox:
ctl.Name = "cbo" & ctl.name
End Select
Next ctl
DoCmd.Close acForm, "FormName", acSaveYes

Problems:
1. If the control was referenced by code anywhere else, that code will no longer work.
2. If any event procedures were written for the original name, those procedures will no longer work.



Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top