Need help coding an OnFocus Event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi - I have little (read NO) coding experience, and I am trying to code an
onFocus event in a form.

Situation: I have 6 fields on the form - "Type", "Gender", and then 4
different age range check boxes. The type field has 3 options: "General
Population", "Family", and "Individual".

Here's my problem - I only want the Gender and age range fields to be
enabled when the user selects "Individual" for the Type field.

Does anyone know how to code this so I can plug it into my OnFocus event (or
is this the wrong event to be using?)

Thanks!
 
BLV,

There is no OnFocus event... I think you mean either the Got Focus event
or the Lost Focus event. And yes, in any case this would not be the
applicable event. I would suggest the After Update event of the Type
control on your form. The code might look something like...
Me.Gender.Enabled = Me.Type = "Individual"
Me.Age_Range.Enabled = Me.Type = "Individual"

It is not clear whether you have 4 separate age range fields represented
by the 4 check boxes. If so, this is probably not the best design. You
probably should only have one Age Range field, assuming each individual
can only be in one aage range at any given time. If you want this on
your form as a choice of check boxes, you can use an Option Group
control with 4 check boxes or option buttons to represent the 4 choices.
 
BLV said:
Hi - I have little (read NO) coding experience, and I am trying to code an
onFocus event in a form.

Situation: I have 6 fields on the form - "Type", "Gender", and then 4
different age range check boxes. The type field has 3 options: "General
Population", "Family", and "Individual".

Here's my problem - I only want the Gender and age range fields to be
enabled when the user selects "Individual" for the Type field.

Does anyone know how to code this so I can plug it into my OnFocus event (or
is this the wrong event to be using?)


GotFocus would be the wrong event for this kind of thing.

You should use the form's Current event to set the enabled
property as dictated by the value of the type field. Here's
the general idea, althought you will have to refine it to
the actual names and values in your program:

Me.Gender.Enabled = (Nz(Me.Type, "") = "Individual")
Me.age1.Enabled = (Nz(Me.Type, "") = "Individual")

Then, you would also need the same line of code in the Type
control's AfterUpdate event so it enables/disables the other
controls when the user enters/changes the type.
 
Back
Top