GoToControl (1 Viewer)

Emma35

Registered User.
Local time
Today, 00:56
Joined
Sep 18, 2012
Messages
455
Hi All,
I have a form containing a Tab Control which has six tab pages containing various fields to be filled by the user. On the sixth page is a Save button. When i press this button i'd like the cursor to go back to a control on Page 1 of the Tab Control called HazardName. What's making it difficult is that i've got subforms within subforms. Can anyone tell me what argument to put into the GoToControl option on the button's macro

Main Form = frm_AddNewRA. This contains the subform frm_SubTask which in turn contains the subform frm_HazardsSub which contains the Tab Control TabCtl0 which contains the control HazardName
 

Emma35

Registered User.
Local time
Today, 00:56
Joined
Sep 18, 2012
Messages
455
Hi...thanks for the link. I've tried a few versions but can't get it to work. I've tried

Forms!frm_AddNewRA!frm_SubTask.Form!frm_HazardsSub.Form!TabCtl0.HazardName

and

Forms!frm_AddNewRA!frm_SubTask.Form!frm_HazardsSub.Form!.HazardName


The button still saves the record but doesn't move back to the control ?
 

vba_php

Forum Troll
Local time
Today, 02:56
Joined
Oct 6, 2019
Messages
2,884
Emma,

check this out: https://www.access-programmers.co.uk/forums/showthread.php?t=147019&

also, this might help with referencing subforms within subforms:

REFERENCE SUBFORM FROM PARENT FORM
Me.subFormName.Form.Action

REFERENCE SUBFORM CONTROL FROM PARENT FORM
Me.subFormName.Form!ControlName.Action

REFERENCE SUBFORM'S SUBFORM CONTROL
Me.subForm2Name.Form.ControlName.Action

REFERENCE SUBFORM of a SUBFORM FROM PARENT FORM (2 NESTED SUBFORMS DEEP)
Me.subForm1Name.Form!subForm2Name.Action

REFERENCE SUBFORM of a SUBFORM CONTROL FROM PARENT FORM (A CONTROL 2 NESTED SUBFORMS DEEP)
Me.subForm1Name.Form!subForm2Name.Form!ControlName.Action

REFERENCE PARENT FORM FROM SUBFORM
Me.Parent.Action

REFERENCE PARENT CONTROL FORM FROM SUBFORM
Me.Parent.ControlName.Action

REFERENCE MAIN FORM FROM SUBFORM 2 LEVELS DEEP
Forms(Me.Parent.Parent.Name).Action

REFERENCE MAIN FORM CONTROL FROM SUBFORM 2 LEVELS DEEP
Forms(Me.Parent.Parent.Name).ControlName.Action

instead of using "GoToControl", try using "SetFocus" in the Action section of the references I provide. It might also be a situation that during a save operation it is impossible to set focus to another control other than the button, but it's been a long time since I've tested anything like that so I can't say for sure.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:56
Joined
Oct 29, 2018
Messages
21,358
Hi...thanks for the link. I've tried a few versions but can't get it to work. I've tried

Forms!frm_AddNewRA!frm_SubTask.Form!frm_HazardsSub.Form!TabCtl0.HazardName

and

Forms!frm_AddNewRA!frm_SubTask.Form!frm_HazardsSub.Form!.HazardName


The button still saves the record but doesn't move back to the control ?
Hi. Is that just a typo because you have spaces in both of those? Have you tried it this way?


Forms!frm_AddNewRA.frm_SubTask.Form!frm_HazardsSub.Form!HazardName


Edit: I see a space in my post too. It must be a forum issue.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:56
Joined
Feb 19, 2002
Messages
42,981
Rather than burying the save button in a subform on a tab, why not put it in the header or footer of the form so that it is always visible and always available? Most of the data will already been saved by the time the user gets to the final subform anyway so the save button is essentially a placebo. That way, the reference will be:

REFERENCE SUBFORM CONTROL FROM PARENT FORM
Me.subFormName.Form!ControlName.Action
 

Micron

AWF VIP
Local time
Today, 03:56
Joined
Oct 20, 2018
Messages
3,476
except that a SUBFORM CONTROL is the control that holds the subform. It isn't a control on the form that's in the subform control. Me.SubformName is misleading too I think. SubformName would be the name of the form in the subform control. Plus anywhere I've seen examples for this, Me is always followed by ! not . I admit . works, but ! is more syntactically correct. The quoted text should say

REFERENCE CONTROL ON SUBFORM FROM PARENT FORM
Me!subFormControlName.Form!ControlName
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:56
Joined
Feb 19, 2002
Messages
42,981
To clarify, the button should be on EACH "outermost" form embedded in the Navigation form.
 

Emma35

Registered User.
Local time
Today, 00:56
Joined
Sep 18, 2012
Messages
455
Thanks everyone for the suggestions. Just to be clear i'm trying to add an action to the macro attached to the button. I tried to convert the macro to VBA and do it that way but it won't work for some reason. The control i'm trying to go to is situated on TabCtl0 which is on the subform frm_HazardsSub
 

Emma35

Registered User.
Local time
Today, 00:56
Joined
Sep 18, 2012
Messages
455
I think someone mentioned it above but it might be the case that you can't save the record and then move the focus to another control at the same time. So i created another smaller button and used this code and it worked

[Forms]![frm_AddNewRA]![frm_SubTask]![frm_HazardsSub]![Page1].SetFocus

When i try to add a little picture of a 'Back Arrow' to the button it gives me a strange error "Object variable or With block variable not set"

Anyone seen that before ?
 

vba_php

Forum Troll
Local time
Today, 02:56
Joined
Oct 6, 2019
Messages
2,884
I think someone mentioned it above but it might be the case that you can't save the record and then move the focus to another control at the same time. So i created another smaller button and used this code and it worked
that was me that said that.

When i try to add a little picture of a 'Back Arrow' to the button it gives me a strange error "Object variable or With block variable not set"
Anyone seen that before ?
check out this thread:

http://www.utteraccess.com/forum/Object-Variable-Block-V-t2010277.html

he was in the same situation you are currently in, trying to manipulate the button on a subform. perhaps that's the problem and access won't allow it no matter what you do.
 

Emma35

Registered User.
Local time
Today, 00:56
Joined
Sep 18, 2012
Messages
455
that was me that said that.


check out this thread:

http://www.utteraccess.com/forum/Object-Variable-Block-V-t2010277.html

he was in the same situation you are currently in, trying to manipulate the button on a subform. perhaps that's the problem and access won't allow it no matter what you do.

Thanks a lot for your help on this. I've read that other thread and it sounds like more trouble than it's worth. I'll just write something on the button. Thanks again to everyone for your time

Em x
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:56
Joined
Oct 29, 2018
Messages
21,358
Thanks a lot for your help on this. I've read that other thread and it sounds like more trouble than it's worth. I'll just write something on the button. Thanks again to everyone for your time

Em x
Hi Em. Good luck with your project.
 

Micron

AWF VIP
Local time
Today, 03:56
Joined
Oct 20, 2018
Messages
3,476
Thanks everyone for the suggestions. Just to be clear i'm trying to add an action to the macro attached to the button. I tried to convert the macro to VBA and do it that way but it won't work for some reason. The control i'm trying to go to is situated on TabCtl0 which is on the subform frm_HazardsSub
Sometimes controls are not properly added to a tab control, and while they appear to be on that control, they are on the form because they appear through the 'layers'. Check that out.

If you want to pursue why not post a copy of your db for analysis?
 

Users who are viewing this thread

Top Bottom