From: Sarah on
I have code like this:

If cboTask.Value = "A2" then
Me!txt_A2_1.Enabled = True: Me!txt_A2_2.Locked = True: ....
... more similar property-setting code here...
End If

This code occurs over 10 times in one of the Subs behind my form. All is
IDENTICAL each time, except for the 'A2' part. This part is always 2
characters long (A2, C6, B1, ...etc.)

Is there a good way to have the lines between the If and the End appear just
once. I'm thinking of using something like Me!txt_XX_1.Enabled... etc, then
subbing in A2, C6, B1... for the Xx. I can't seem to get the syntax right.

Thanks for any assistance
Sarah
From: Dirk Goldgar on
"Sarah" <Sarah(a)discussions.microsoft.com> wrote in message
news:8C64A3FE-C369-4E40-95E4-979146E58A71(a)microsoft.com...
>I have code like this:
>
> If cboTask.Value = "A2" then
> Me!txt_A2_1.Enabled = True: Me!txt_A2_2.Locked = True: ....
> ... more similar property-setting code here...
> End If
>
> This code occurs over 10 times in one of the Subs behind my form. All is
> IDENTICAL each time, except for the 'A2' part. This part is always 2
> characters long (A2, C6, B1, ...etc.)
>
> Is there a good way to have the lines between the If and the End appear
> just
> once. I'm thinking of using something like Me!txt_XX_1.Enabled... etc,
> then
> subbing in A2, C6, B1... for the Xx. I can't seem to get the syntax
> right.


So cboTask holds the 2-character identifier that should be used in
constructing the control names? Try this:

Me.Controls("txt_" & cboTask & "_1").Enabled = True

The need to do this suggests that maybe your database could be better
structured. Not knowing much about what you're doing, though, I won't rush
to judgement.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)