Go to control

J

julief

I am new to coding and hope someone can point me in the right direction.

I have a form [stock requisitions] on which is a sub form [stock requisition
detail], when a user wants to add a new record I have included a command
button on the main form to add new record but want the user to always go to
the same field [req note] which is at the beginning of the main form.

I have tried [stock requisitions].Form.[req note].Set focus but get an error
message saying it cant find the field name.

Any help would be most welcome.

Thanks in anticipation.
 
K

Keith Wilby

julief said:
I am new to coding and hope someone can point me in the right direction.

I have a form [stock requisitions] on which is a sub form [stock
requisition
detail], when a user wants to add a new record I have included a command
button on the main form to add new record but want the user to always go
to
the same field [req note] which is at the beginning of the main form.

I have tried [stock requisitions].Form.[req note].Set focus but get an
error
message saying it cant find the field name.

Any help would be most welcome.

Thanks in anticipation.

You need to set the focus to the name of the *control* (a text box by the
sound of it), not the field name. Access usually names a text box with the
same name as the field it's bound to, which can be confusing, so I generally
change it. Hence, if a field has the name "req note" I would rename the
bound text box "txtReqNote". So the code would be.

Me.txtReqNote.SetFocus

It's also good practice to omit spaces from field names, so I would have
named the field "ReqNote".

HTH - Keith.
www.keithwilby.com
 
D

Douglas J. Steele

Keith Wilby said:
julief said:
I am new to coding and hope someone can point me in the right direction.

I have a form [stock requisitions] on which is a sub form [stock
requisition
detail], when a user wants to add a new record I have included a command
button on the main form to add new record but want the user to always go
to
the same field [req note] which is at the beginning of the main form.

I have tried [stock requisitions].Form.[req note].Set focus but get an
error
message saying it cant find the field name.

You need to set the focus to the name of the *control* (a text box by the
sound of it), not the field name. Access usually names a text box with
the same name as the field it's bound to, which can be confusing, so I
generally change it. Hence, if a field has the name "req note" I would
rename the bound text box "txtReqNote". So the code would be.

Me.txtReqNote.SetFocus

It's also good practice to omit spaces from field names, so I would have
named the field "ReqNote".

Actually, since the text box is on a subform, it's necessary to set focus to
the subform control first.

Make sure that the name of the subform control is [stock requisitions]:
depending on how the subform was added, the name of the subform control may
be different than the name of the form being used as a subform.

Me.[stock requisitions].SetFocus
Me.[stock requisitions].Form.[req note].SetFocus

(and I agree whole-hearted with Keith that you shouldn't use spaces in your
names!)
 
K

Keith Wilby

Douglas J. Steele said:
the same field [req note] which is at the beginning of the main form.

Actually, since the text box is on a subform, it's necessary to set focus
to the subform control first.

Hi Doug,

I inferred from the OP that it was on the main form. Either way I think
they have enough to go on now.

Regards,
Keith.
 

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