syntax help requested

  • Thread starter Thread starter Sarah
  • Start date Start date
S

Sarah

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
 
Sarah said:
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.
 
Back
Top