ok, i've been trying to get some help on this for a while, but i'm not sure if there's just no way or what.
I have textbox fields named 1,2,3...10 all linked to a table w/ a unique index for each record
For each record I want to add fields 1 to 10 and display the result in txtbox "result". These fields are in a subform. To avoid typing forms![Mainform].[Subform].form.1 + forms![Main.... etc. ten times, is there a way to use a loop?
I've had suggestions like forms![Mainform].[Subform].Form!(i)
but that doesn't work.
Its that pesky !, thake it out and should work great. Actaully, I think you're wanting the Controls function instead of the forms.
use something like
dim i as integer, val as integer
i = 0
for i = 0 to 9
val = val + forms![Mainform].[Subform].Controls(i)
result = val
If I'm correct, that actually references the index number of the control and not the control's name. I usually name the text boxes something like txt0, txt1 just to be clearer.. if you do that just modify it to Controls("txt" & i) You can reference any part of that control by using the . operator after it too
The forms() function would be used to do something like:
thanks. that sort of helps. is there no way to reference the actual name or value of the field? I don't particularly want to change the names from 1, 2, 3... because they are headers for my datasheet subform.