After Update

J

jlute

Private Sub Form_AfterUpdate()
DoCmd.GoToControl Forms![frmPKProjects]![sfrmProjectsTasks]!
[sfrmProjectsTasksResponsibles].Form![cbResponsible]
DoCmd.GoToRecord , , acNewRec

End Sub

I'm trying to automatically move the cursor to:
sfrmProjectsTasksResponsibles.cbResponsible but the code's not
working.

Can anyone please highlight the error(s) of my way?

THANKS!
 
S

Stuart McCall

Private Sub Form_AfterUpdate()
DoCmd.GoToControl Forms![frmPKProjects]![sfrmProjectsTasks]!
[sfrmProjectsTasksResponsibles].Form![cbResponsible]
DoCmd.GoToRecord , , acNewRec

End Sub

I'm trying to automatically move the cursor to:
sfrmProjectsTasksResponsibles.cbResponsible but the code's not
working.

Can anyone please highlight the error(s) of my way?

THANKS!

It looks to me like you've got an extra "sfrmProjectsTasks" in there. Try:

DoCmd.GoToControl
Forms![frmPKProjects]![sfrmProjectsTasksResponsibles].Form![cbResponsible]

or, better still:

Forms![frmPKProjects]![sfrmProjectsTasksResponsibles].Form![cbResponsible].SetFocus

(watch out for word-wrap. Both lines of code are one-liners)
 
N

NoodNutt

G'day

I'm not an MVP Guru, and i'm dead certain one of them will correct me if i'm
wrong.

You should put this in the last control of your mainforms after_update not
the forms after_update.

MyLastControl after_update()

Me![frmPKProjects]![sfrmProjectsTasks]![sfrmProjectsTasksResponsibles].SetFocus


In the Subforms OnGotFocus()
Docmd.gotoControl "cbResponsible"

HTH
Mark.
 
J

jlute

Thanks, Stuart.

Actually, there's nothing extra there. The 3 forms are valid and their
spelling is correct.
DoCmd.GoToControl Forms![frmPKProjects]![sfrmProjectsTasks]!
[sfrmProjectsTasksResponsibles].Form![cbResponsible]
This returns: An expresion you entered is the wrong data type for one
of the arguments.

To NoodNutt's point: that's a great idea however the subform doesn't
have a "last control". There are several and each one can be updated
at anytime. I only need to go to [cbResponsible] when a new record is
entered into sfrmProjectsTasks and then updated. Hmmm...perhaps I'm
going about this entirely wrong...?

Private Sub Form_AfterUpdate()
   DoCmd.GoToControl Forms![frmPKProjects]![sfrmProjectsTasks]!
[sfrmProjectsTasksResponsibles].Form![cbResponsible]
   DoCmd.GoToRecord , , acNewRec
I'm trying to automatically move the cursor to:
sfrmProjectsTasksResponsibles.cbResponsible but the code's not
working.
Can anyone please highlight the error(s) of my way?

It looks to me like you've got an extra "sfrmProjectsTasks" in there. Try:

DoCmd.GoToControl
Forms![frmPKProjects]![sfrmProjectsTasksResponsibles].Form![cbResponsible]

or, better still:

Forms![frmPKProjects]![sfrmProjectsTasksResponsibles].Form![cbResponsible].­SetFocus

(watch out for word-wrap. Both lines of code are one-liners)
 
B

boblarson

If you have more than one subform, you need to use the correct syntax.
Check this out as it might help you grasp that better.
http://www.btabdevelopment.com/main...rhowtoreferencesubforms/tabid/76/Default.aspx

Your current reference needs to be:

Forms!frmPKProjects.sfrmProjectsTasks.FORM.sfrmProjectsTasksResponsibles.FORM.cbResponsible

A couple of things:
1. When you are dealing with subforms, you are actually dealing with two
parts - the subform CONTAINER (that which houses the subform on the main
form) and the subform itself.

2. The subform and subform container can be named the same, but are not
necessarily so. You need to check before writing the code. If they are the
same then it simplifies things but it doesn't really matter if it is, or
isn't, because you just have to refer to the container.

3. When you are doing things, like setting the recordsource on the subform,
you are not really requerying the container, as it doesn't have a requery
method, but the subform itself does. So, when you are referring to a
property, or method, on the actual subform (not the container), you need to
have the subform container name and then .Form. between the container name
and the method, or property, so Access knows you want to refer to the form's
method or property and not the container's method or property.


--

Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP
Free Access Resources at http://www.btabdevelopment.com
 

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