I need to refer to a text field by using a variable for its name.

Hello Experts!

I think this should be an easy question.  I've done it before but don't remember how!

I have a form that has space for 20 images.
The image "boxes" are named imgbox01, imgbox02, imgbox03 and so forth

The images that I want to display are in the array arrImage(20)

My code loops through each image in arrImages() from n=1 to 20

when I decide to display an image in a specific box, for example, imgbox2, i need to programmatically refer to this image box.

Here is an sample of my code:
'Put the image stored in location nn in the array in the imgbox specified by n
For n=1 to 20
  if <some condtion> then
     Forms!frmPhotoAlbum.Image4.Picture = arrImage(nn)

Only, I do not want to hard code 4 into this line, as sometimes it will go into possition 6, or whatever the value of n currently is

So, how do I incoporate the value of n into the name of the imagebox?
in other words, if n=2 how do I code so that I can replace the 4 with the value for n?
Forms!frmPhotoAlbum.Image4.Picture =arrImage(2)

Who is Participating?
Rey Obrero (Capricorn1)Connect With a Mentor Commented:

use this format

Forms("frmPhotoAlbum")("Image" & n).Picture =arrImage(2)
Rey Obrero (Capricorn1)Commented:

use this format

Forms("frmPhotoAlbum")("Image" & n).Picture =arrImage(n)
Where do you keep the number of the image in the arrray?  I assume the array element is a string, structured along the lines of:

pcalabriaAuthor Commented:

Thanks CAP!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.