Varible field name

chuckster

Registered User.
Local time
Today, 20:10
Joined
Oct 4, 2000
Messages
52
I have many fields whose names are a1, a2, a3 etc.

I want some code that will assign the field name to a variable then run the code then loop and assign the varible to the next field etc. I'm not doing it right and don't know what to do.

This simple thing without the loop doesn't work either.

dim strField as string
dim intField as integer

intField = 1

strField = "me.a" & intField.

if blah then strField.visible = false

VB doesn't consider the strfield as an object or something.

Do I need to dim strField as something else or am I going about this totally the wrong way?

Thanks
 
Hi Chackster
I assume that your fields are bound to controls on you form.
If that is the case you could use something similar to:

For i = 1 to No_Of_Fields
if blah then me.controls("a"&i).visible = false
next i

Hope it helps
Kaspi
 
That's It thanks heaps.

Chuckster
 
I wouldn't name fields like that, the next programmer to look at this is going to hate you.

Did you know that there is a much easier way to work with groups of form fields? You can use the "Tag" property to give a set of fields a name, then modify the properties of everything with that tag.

Let's say you give some controls a Tag of "AcctgFields". The code goes like this:
Dim frmMyForm As Form
Dim ctlMyCtls As Control
' more code
Set frmMyForm = Forms!fMyForm
For Each ctlMyCtls In frmMyForm.Controls
If 'some logic here
If ctlMyCtls.Tag = "AcctgFields" Then
ctlMyCtls.Visible = True 'let them see it
ctlMyCtls.Enabled = True 'let them use it
End If
Next ctlMyCtls
End If
' more code
Set frmMyForm = Nothing
 
Thanks Chris,

I really wish now I knew that at the time. I thought there must be some grouping option like that I just didn't know what. I can think of 500 uses for that tag feature.

The field names are actually coordinates of size and colours fields a1,a2,a3... b1,b2,b3 etc.

ps I think that another programmer would probably laugh at my code before he hated me. :-) but point taken.

Cheers

Chuckster

[This message has been edited by chuckster (edited 09-04-2001).]
 

Users who are viewing this thread

Back
Top Bottom