Yes/No Response Influences GoTo Com. My Code Not Working

T

TravelingHT

Dear All:

I have a form with a subform, I want on the choice of "Yes", in the Combo
Box, for the tab order to change to a txt box in the sub form of the current
form.

I am often confused by two points. (And possiably more, the unknown unkonwn,
but lets leave that one to that Dick Chany. )

1. If I am puting code at the form level, then I should be using the
responses, i.e.
"Yes" Instead of "-1" and "No" instead of "0" ?
2. Should I be referencing the "Value" of the control or something else?

This is the code I currently have which is not working.


Private Sub EverHiredTemporaryHistologist_Exit(Cancel As Integer)
If Me.EverHiredTemporaryHistologists.Value = 0 Then
DoCmd.GoToControl (Me.RoleINHiringDecision)

ElseIf Me.EverHiredTemporaryHistologists.Value = -1 Then
DoCmd.GoToControl (Form!sbfrmTempHTMostImportant.LabManagerResponse)
End If
End Sub

Thanks in advance

Traveling Tech
 
D

Douglas J. Steele

The reason the code's not working is because you cannot refer directly to
forms being used as subforms: you must go through the parent.

The syntax for referring to a control on a subform is:

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform

Note that depending on how you added the subform, the name of the subform
control may not be the same as the name of the form being used as a subform.

You may find http://www.mvps.org/access/forms/frm0031.htm at "The Access
Web" to be useful.

And in general, it's better to use the SetFocus method, rather than the
GoToControl method. The "trick" is that you need to set focus to the subform
first:

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.SetFocus
Forms!NameOfParentForm!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform.SetFocus
 
D

Douglas J. Steele

Note that there's word-wrap on the second SetFocus statement

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform.SetFocus

should all be on one line.
 
T

TravelingHT

Thank you for the help.

I am having some problem understanding exactly what you are saying.

This is the code that I now have after your timly intervention:

Private Sub EverHiredTemporaryHistologist_Exit(Cancel As Integer)
If Me.EverHiredTemporaryHistologists = "No" Then
Forms!frmQuestionnaireResponses!HRRelationshipSpeed.SetFocus

ElseIf Me.EverHiredTemporaryHistologists = "Yes" Then
Forms!frmQuestionnaireResponses!sbfrmTempHTMostImportant.LabManagerResponse.SetFocus
End If
End Sub

I am not sure if you wanted me to put both of the following lines after each
if statement. or if you want one line for the control in the current form and
the second line for the control that is in the subform.?

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.SetFocus
Forms!NameOfParentForm!NameOfSubformControlOnParentForm.:-
(Form!NameOfControlOnSubform.SetFocus)

How is the braketed stuff supost to work, is this a separate line? Is the
concatenation correct? I normally can follow the logic of telling the
computer where to go, go to forms, look for this form, look for the object
with this name on the form, but at that point we seem to be saying "OK there
is a form in this controls name, but I am not going to tell you the name is,
just "Forms!" and from there go the Subform control
called"NameOfControlOnSubform". Set Focus

There is evidence of life on other planets I am sorry if you are starting to
question its existance at my keyboard.

TravelingHT

I am having trouble with this. Sorry.

And thanks in advance.

Also the logic, I do not understand why it would not be.

Forms!NameOfForm!NameOfSubForm.NameOfSubFormControl.

OR

Forms!NameOfForm!NameOfSubFormControlONParentForm.

But why

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform.SetFocus
 
D

Douglas J. Steele

Let's try using shorter names so that there won't be word-wrap in the
response!

Assume F1 is the name of the parent form, S1 is the name of the subform
control on form F1 and C1 is the name of the control on the subform to which
you want focus set.

To set focus on the control on the subform, you need the following two
statements, one after the other. The first one sets focus on the subform.
Unless that's done, you cannot set focus to a control on the subform:

Forms!F1!S1.SetFocus
Forms!F1!S1.Form!C1.SetFocus

The important things to remember are that S1 is the name of the subform
control on the parent form (which may be different than the name of the form
being used as a subform), and that you need to include .Form after the
subform control name in order to refer to anything on the subform.
 

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