Concatenate fieldname

Poppa Smurf

Registered User.
Local time
Today, 14:56
Joined
Mar 21, 2008
Messages
448
I have a number of fields on a form to display and capture data. The fields in each column has the following format fieldname_number e.g. period_1, to period_10, name_1 to name_10 etc.

Is there a way that I can use a counter to make these fields invisible or visible as required?

As an example for each cycle of the counter it would be period_1.visible=true, name_1.visible=true then period_2.visible=true, name_2.visible=true etc. until the end of the counter
 
Try this;
Lets say your counter is named "i", then you could refer to your field like so:

Me.Controls("period_" & i).Visible = True
 
Rick

Thank you, it saved a lot of coding.
 
I have a number of fields on a form to display and capture data. The fields in each column has the following format fieldname_number e.g. period_1, to period_10, name_1 to name_10 etc.

Your problem begins with poor data structure. Fields with numbered suffixes should invariably ring normaization alarms. The existing structure will continue to cause problems as you try to process the data.

This data should be stored as separate records for each period.

BTW. You should also use correct terminology. As you probably gathered in Rick's answer, the boxes on forms are called Controls. Fields are in tables, queries and recordsets. The only place a form had fields is in its recordset. It really matters when you try to refer to objects.

The "columns" in a table or datasheet mode form are called fields. Columns are in listboxes and comboboxes. (Unfortunately Microsoft doesn't help matters by used incorrect terminology in some places.)
 

Users who are viewing this thread

Back
Top Bottom