How to avoid endless loop?

J

JeffSomDal

I am attempting to set focus to a field and then return focus back to the
field that initiated this process. My attempts have resulted in creating an
endless loop error. Any help is greatly appreciated.

Form design:
I have 4 fields in my main form.
Each field corresponds to a separate page in a tab control contained in a
subForm on the MainForm.
Each page of the tab control contains an image that illustrates the
corresponding MainForm field.
This layout is required due to limited screen space. Not all images can be
displayed at the same time. The desired result is to show the corresponding
image in the subForm when its MainForm field has the focus.

My failed attempt to achieve this end...(Endless loop coding):

On Enter event of Field1:
Forms![fMainForm]![child_subForm]![TabCtl_Images].Pages(0).SetFocus
Me.Field1.SetFocus

On Enter event of Field2:
Forms![fMainForm]![child_subForm]![TabCtl_Images].Pages(1).SetFocus
Me.Field2.SetFocus

etc...
 
S

Steve Sanford

Not to be a nitpicker..... well, I guess I am going to be one

..... no offence intended....

-Tables have fields
-Forms have controls
-Controls have events
- Fields do not
-Tables/Fields store data
-Forms/Controls view/Display the data
-Forms can be bound to a Table/Query

-If a Form is bound to a Table/Query, then a control can be bound to a field



Not enough info to try and figure out why you are trying to do this. Storing
images in your database would make it huge!


OK, in answer to your question, try using the click event:

Private Sub Control1_click()
Forms![fMainForm]![child_subForm]![TabCtl_Images].Pages(0).SetFocus
Me.Control1.SetFocus
End Sub

Private Sub Control2_click()
Forms![fMainForm]![child_subForm]![TabCtl_Images].Pages(0).SetFocus
Me.Control1.SetFocus
End Sub

:D

HTH
 
J

JeffSomDal

Steve Sanford said:
Not to be a nitpicker..... well, I guess I am going to be one

.... no offence intended....

-Tables have fields
-Forms have controls
-Controls have events
- Fields do not
-Tables/Fields store data
-Forms/Controls view/Display the data
-Forms can be bound to a Table/Query

-If a Form is bound to a Table/Query, then a control can be bound to a field



Not enough info to try and figure out why you are trying to do this. Storing
images in your database would make it huge!


OK, in answer to your question, try using the click event:

Private Sub Control1_click()
Forms![fMainForm]![child_subForm]![TabCtl_Images].Pages(0).SetFocus
Me.Control1.SetFocus
End Sub

Private Sub Control2_click()
Forms![fMainForm]![child_subForm]![TabCtl_Images].Pages(0).SetFocus
Me.Control1.SetFocus
End Sub

:D

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


JeffSomDal said:
I am attempting to set focus to a field and then return focus back to the
field that initiated this process. My attempts have resulted in creating an
endless loop error. Any help is greatly appreciated.

Form design:
I have 4 fields in my main form.
Each field corresponds to a separate page in a tab control contained in a
subForm on the MainForm.
Each page of the tab control contains an image that illustrates the
corresponding MainForm field.
This layout is required due to limited screen space. Not all images can be
displayed at the same time. The desired result is to show the corresponding
image in the subForm when its MainForm field has the focus.

My failed attempt to achieve this end...(Endless loop coding):

On Enter event of Field1:
Forms![fMainForm]![child_subForm]![TabCtl_Images].Pages(0).SetFocus
Me.Field1.SetFocus

On Enter event of Field2:
Forms![fMainForm]![child_subForm]![TabCtl_Images].Pages(1).SetFocus
Me.Field2.SetFocus

etc...
 

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