SetFocus Question

  • Thread starter Thread starter Bill Sturdevant
  • Start date Start date
B

Bill Sturdevant

I have a subform that is a 3-year calendar. On the main
form I have Project start date and Project end date
fields. Depending on the values entered in those 2
fields, I enable only the calendar fields in the subform
that are within the range of the project start and end
dates.

Is there a way I can tell Access to set the focus to the
first enabled field on the calendar form? What happens
now is if the Project start date is changed from 12/1/2004
to 6/1/2004, the focus on the subform remains on the
December 2004 field.
 
Hi Bill,

You can go to the subform properties and under the Event tab, click "On Open" and select code builder

In code builder, type the following code

Docmd.Insertfieldname.SetFocu

Replace Insertfieldname with the name of the field you want to set focus on. You may have to click on that field and look for the object name in the formatting toolbar to find the field name

Once you open the form, it should automatically set the focus to the field you want

Hope that helps
Matt
 
Thanks for the response. I know I can do as you suggest,
but that would mean I would have to calculate which field
I wanted first.

What I was hoping was there was a way to say "set the
focus to whichever field is the first one in the tabbing
order that is enabled". That way, I would not have to
know beforehand which field I wanted.

-----Original Message-----
Hi Bill,

You can go to the subform properties and under the Event
tab, click "On Open" and select code builder.
In code builder, type the following code:

Docmd.Insertfieldname.SetFocus

Replace Insertfieldname with the name of the field you
want to set focus on. You may have to click on that field
and look for the object name in the formatting toolbar to
find the field name.
 
Bill said:
I have a subform that is a 3-year calendar. On the main
form I have Project start date and Project end date
fields. Depending on the values entered in those 2
fields, I enable only the calendar fields in the subform
that are within the range of the project start and end
dates.

Is there a way I can tell Access to set the focus to the
first enabled field on the calendar form? What happens
now is if the Project start date is changed from 12/1/2004
to 6/1/2004, the focus on the subform remains on the
December 2004 field.


Nothing built in will do that, but if you already have a way
to disable the "out of range" controls, then haven't you
also determined the first one that is enabled?
 
-----Original Message-----



Nothing built in will do that, but if you already have a way
to disable the "out of range" controls, then haven't you
also determined the first one that is enabled?
The "out of range" controls are disabled by Conditional
Formatting.

Since there is nothing automatic, I will have to resort to
code.
 
-----Original Message-----
Bill said:
The "out of range" controls are disabled by Conditional
Formatting.

Since there is nothing automatic, I will have to resort to
code.


I can't think of any other way, Bill. OTOH, if the controls
have nice uniform names that follow the tab order, it would
be a pretty simple loop:

For K = 1 To N
If Me("Month" & K).Enabled Then
Me("Month" & K).SetFocus
End If
Next K
 
Back
Top