Solved

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

Posted on 2011-09-10
4
218 Views
Last Modified: 2012-05-12
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)
next

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)

0
Comment
Question by:pcalabria
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 36516377


use this format

Forms("frmPhotoAlbum")("Image" & n).Picture =arrImage(2)
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36516380


use this format

Forms("frmPhotoAlbum")("Image" & n).Picture =arrImage(n)
0
 
LVL 44

Expert Comment

by:GRayL
ID: 36516870
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:

c:\data\images\myPic.jpg
0
 

Author Closing Comment

by:pcalabria
ID: 36518820
Perfect!

Thanks CAP!!!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question