Initialize form fields

D

dapmco

Is there a way to build a string and execute the command to initialize
fields on a from within a loop, something like below? I thought the
eval command might work but doesnt seem to.

arry(1) = "Local"
arry(2) = "State"
arry(3) = "Federal"


For I = 1 To 3


TheString = "[Forms]![QBF]![LevelOfInterestUnbound]!" & arry(I) & " =
False""
Eval (TheString)


Next


Dave Taylor
 
D

Douglas J. Steele

What are the various objects with which you're dealing? If I had to guess
(which I do, because you didn't say <g>), I'd say QBF is a form,
LevelOfInterestUnbound is a subform, and Local, State and Federal are fields
on the LevelOfInterestUnbound form.

On that assumption, make sure that the name of the control on QBF that holds
the subform is named LevelOfInterestUnbound. Depending on how you added the
LevelOfInteresUnbound form as a subform, the name of the control may be
something other than LevelOfInterest (say, Child1). You need to use the name
of the subform control, not the name of the form being used as a subform.
Then, because you're referring to the subform control, you need to indicate
somehow that you want the form being used as a subform, which you do by
using .Form. Finally, you can't use variables in a reference like that, but
you can use variables with the Controls collection.

In other words, you want:

For I = 1 To 3
[Forms]![QBF]![NameOfSubformControl].Form.Controls(arry(I)) = False
Next

Of course, with only 3 controls, it's probably easier simply to use

[Forms]![QBF]![NameOfSubformControl].Form!Local = False
[Forms]![QBF]![NameOfSubformControl].Form!State = False
[Forms]![QBF]![NameOfSubformControl].Form!Federal = False

If my assumptions were incorrect, post back with more details.
 
Top