Full Version: Change/add To Name Of Textbox
UtterAccess Forums > Microsoft® Access > Access Forms
I have a form with up to 12 name and address boxes used as a telephone tree for a community blockwatch. Eack blockwatch captain is responsible for up to 12 homeowners. I get all the data for the form but i'm trying to dynamically change the textbox names after each set of info is entered into each separate box.
!.Name1 = rst.Name
!.Addr1 = rst.Addr
There are 12 each of "Name1, Addr1" text boxes in each form box. I'm trying not to have to code the whole form from 1 to 12 for each box on the form. How can I modify the textbox name from "!.Name1" to "!.Name2" and "!.Addr1" to "!.Addr2" and so on?
Hi Brad,
You could try something like:
Dim x As Integer
x = 1
'start rst loop here
Me.Controls("Name" & x) = rst![Name]
x = x + 1
Please note that "Name" is a *reserved* word in Access. You should try and avoid using it for your object/field names.
Hope that helps...
Click to view attachmentI must be doing something wrong. Mt form controls are named "N1 thru N12" . I have the form open. Access does not seem to find the form or something. I started by using "N" rather than "N1" to allow for the increment. Code sample attache.
1 through N12 should be the names of the controls on your form. Also, I had no idea what your setup looks like so I didn't include it in the code sample I posted, but you probably should include some test for x = 12 in there somewhere to make sure you don't exceed the number of controls on your form.
If you select one of the controls you are trying to assign a value while in Design View, what is in the Name property? That would be what you need to use in your code.
Hope that helps...
I just made one change and it all works fine. Thanks for the help.
im Tree As Form
Set Tree = Forms!frmtree
Dim X As Integer
X = 1
Do Until rst.EOF

Tree("N" & X) = rst!LastName & " ," & rst!FirstNames
Tree("a" & X) = rst!Address
Tree("hp" & X) = rst!HomePhone
Tree("cp" & X) = rst!CellPhone


X = X + 1
Glad to hear you got it to work. Good luck with your project.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.