SetFocus on TextBox

G

Gordon Dale

I am trying to give a TextBox focus on opening a form but
if I use Forms!Detail!.Sequence No.SetFocus an error
message tels me that this type of property is not
available for this type of object. Yet HELP tells me that
to use SetFocus do this: SetFocus Method Example

The following example uses the SetFocus method to move
the focus to an EmployeeID text box on an Employees form:

"Forms!Employees!EmployeeID.SetFocus"

This is my attempt

Details is the Name of the SubForm opened with the command
stDocName = "Form 40 Register Supplier"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Detail!SequenceNo.SetFocus (Trying to give
TextBox SequenceNo the Focus here)

I would oblige if anyone can help

Regards

Gosher
 
J

Jim Allensworth

I am trying to give a TextBox focus on opening a form but
if I use Forms!Detail!.Sequence No.SetFocus an error
message tels me that this type of property is not
available for this type of object. Yet HELP tells me that
to use SetFocus do this: SetFocus Method Example

The following example uses the SetFocus method to move
the focus to an EmployeeID text box on an Employees form:

"Forms!Employees!EmployeeID.SetFocus"

This is my attempt

Details is the Name of the SubForm opened with the command
stDocName = "Form 40 Register Supplier"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Detail!SequenceNo.SetFocus (Trying to give
TextBox SequenceNo the Focus here)

You need to go throught the subform's form object to get to it's
controls. Try this...

Forms!Detail.Form!SequenceNo.SetFocus

I'm assuming that Details is the name of the subform control. You need
to go through the control to get to it's Form object.

- Jim
 
B

Bruce M. Thompson

This is my attempt
Details is the Name of the SubForm opened with the command
stDocName = "Form 40 Register Supplier"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Detail!SequenceNo.SetFocus (Trying to give
TextBox SequenceNo the Focus here)

How can "Details" be the name of the form you are opening when you are clearly
opening a form designated by the value assigned to stDocName? Are you saying
that "Details" is the name of a subform on the form you are opening? If so, the
proper syntax to set the focus to a control on that subform from within the
existing procedure would be:

Forms(stDocName).SubformControlName.Form.SetFocus
Forms(stDocName).SubformControlName.Form.SequenceNo.SetFocus

Where "SubformControlName" is the name of the subform *control* on the main form
(not the name of the subform itself, although both may share the same name). You
need to set the focus to the subform control in addition to setting the focus to
the control on the subform because the subform object can have focus set to a
particular control without the subform actually *having* the focus (confusing,
isn't it?).

Please note that you have used "Detail" as a name for an object and "Detail" is
a reserved word in Access (it just happens to be the "Name" of the "Detail"
section of a form). This can cause problems wherein Access can become confused
about what you are referencing.
 
G

Gordon Dale

Thanks for the clarification Bruce

I will try that and let you know

Regards

Gordon Dale
 
G

Guest

Bruce
Simpler than I thought, though I am sure this is one of
the combo's I tried before resorting to asking

stDocName = "Form 40 Register Supplier"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms(stDocName).SequenceNo.SetFocus

Works a treat

Thanks again

Gordon
 
G

Guest

Jim
Simpler than I thought, though I am sure this is one of
the combo's I tried before resorting to asking

stDocName = "Form 40 Register Supplier"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms(stDocName).SequenceNo.SetFocus

Works a treat

Thanks again

Gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top