View Full Version : Looping thru Alphabet


craigachan
04-10-2008, 04:07 AM
I have a series of fields on a form. Each field name is a number 1 thru 32. I use a loop to set field properties


Param = 1
For z = 1 To 32
If (Me(Me.ParamB & Me.Param).Visible = True) Then
Me(Me![ParamB] & Me!Param).Visible = False
Me(Me!ParamL & Me!Param).Visible = False
Me(Me!ParamE & Me!Param).Visible = False
Me(Me!ParamT & Me!Param) = Null
End If
Param = Param + 1
Next z


I also have on the same form a series of field whose names are alphabets "a" thur "t"

I would also like to loop thru these fields to do the same thing. Is there any way to do this? I have tried the following code but it doesn't work. I'm thinking I need to set up temp fields to reassign each of these fields a number then loop thru it. I havn't tried it yet. but I'm wondering if there is a way to loop through the alphabet.


Param = "A"

For z = "A" To "t"

If (Me(Me.ParamB & Me.Param).Visible = True) Then
Me(Me![ParamB] & Me!Param).Visible = False
Me(Me!ParamL & Me!Param).Visible = False
Me(Me!ParamE & Me!Param).Visible = False
Me(Me!ParamT & Me!Param) = Null
End If

Param = Param + 1
Next z

gemma-the-husky
04-10-2008, 04:29 AM
you have two functions available

the asc function return values of chars or
chr function to set a char

so asc("A") is 65
or chr(65) is "A"

so maybe try

for x=1 to 20
testchar = chr(64+x) etc
....
next x


will set testchar to the values A thru T

craigachan
04-10-2008, 06:31 AM
:rolleyes:Thanks, that worked great. I just want to say that I really appreciate all your help. This forum is great. I try to read my VB Manual to learn this stuff. But the manual is often difficult for me to understand. You all are great!

gemma-the-husky
04-11-2008, 01:03 AM
craig, i think a lot of the manuals are good on queries/forms/reports - eventually though, you need some vba to do certain things, and the manuals are less good in this area unfortunately.

the best book i have found is Access Cookbook - its doesnt deal with everything, but it does offer solutions to a whole seres of real world problems, and doesnt take 500 pages repeating the basics you already know


note that the code i provided in theory deals with upper case letters only - lower case letters have different ascii codes - although amazingly having said that, somehow access by default does not distinguish between upper and lower case letters - and i cant imagine how it achieves this! - its really useful though

it does mean if you start using other languages you may find things you take for granted (like this) dont work in quite the same way.