Form, Subform: SetFocus Code

G

Guest

My setfocus code is not working.

There are 4 pieces ... 1 piece for On Exit property of "last field" in Main
Form ... 1 piece for On Exit property of "last field" in 1st Subform ... 1
piece for On Exit property of "last field" in 2nd Subform ... 1 piece for On
Exit property of "last field" in 3rd Subform.

Code is reproduced at bottom. Can anybody see what's wrong?

My Goal ... Tab thru all fields on Form. Form consists of Main Form with 3
Subforms. (The Main Form has a few fields, and each Subform has a few
fields.)

Problem #1 ... When I attempt to Tab from "last field" in 1st Subform to
"first field" in 2nd Subform, the cursor does "not" move to 2nd Subform.
Instead, it moves back to "first field" of 1st Subform.

Problem #2 ... When I attempt to Tab from "last field" in 2nd Subform to
"first field" in 3rd Subform, the cursor does "not" move to 3rd Subform.
Instead, it moves back to "first field" of 2nd Subform.

Exception to Problems ... When I Tab from "last field" in Main Form to
"first field" in 1st Subform, the Tab works. Likewise, when I Tab from "last
field" in 3rd Subform to "first field" in Main Form, the Tab works.

For Code Reference ... what follows are names of Main Form, Subforms, and
fields:

Main Form = BM_DataEntry ... first field = PageID ... last field = Link
1st Subform = Details_Subform ... first field = DetailID ... last field =
PageID
2nd Subform = SubjectHead_Subform ... first field = SubjectID ... last field
= PageID
3rd Subform = Author_Subform ... first field = AuthorID ... last field =
PageID

CODE ...

1.) Code for Tab from "last field" in Main Form to "first field" in 1st
Subform:

Private Sub Link_Exit(Cancel As Integer)
Forms![BM_DataEntry]![Details_Subform].Form![DetailID].SetFocus
End Sub

2.) Code for Tab from "last field" in 1st Subform to "first field" in 2nd
Subform:

Private Sub PageID_Exit(Cancel As Integer)
Forms![BM_DataEntry]![SubjectHead_Subform].Form![SubjectID].SetFocus
End Sub

3.) Code for Tab from "last field" in 2nd Subform to "first field" in 3rd
Subform:

Private Sub PageID_Exit(Cancel As Integer)
Forms![BM_DataEntry]![Author_Subform].Form![AuthorID].SetFocus
End Sub

4.) Code for Tab from "last field" in 3rd Subform to "first field" in Main
Subform:

Private Sub PageID_Exit(Cancel As Integer)
Forms![BM_DataEntry]![PageID].SetFocus
End Sub
 
M

Marshall Barton

When setting the focus to a control in a subform, you should
first set the forcus to the subform control.

Private Sub PageID_Exit(Cancel As Integer)
With Forms![BM_DataEntry]![SubjectHead_Subform]
.Setfocus
.Form![SubjectID].SetFocus
End With
End Sub
 
G

Guest

With your help, I can now advance thru each field in Main Form, and its 3
Subforms.

However, two new problems have occurred!

Problem #1 ... When I move out of Subform1 and into Subform2, the record
count for Subform1 changes to Record2. Yet, I haven't finished data entry
for Record1, as data entry into Subform2 and Subform3 has not yet occurred.

Problem #2 ... When I proceed to complete data entry of Subform2 and
Subform3 (for Record1) and close, and then open the Main Form, all entered
data is present, and the record count of Main Form, Subform1, Subform2, and
Subform3 is at Record1. However, as I enter Record2 data into Main Form and
Subforms, the record count remains at Record1. Effectively, Record2
overwrites Record1.

My Database Design ... 4 tables, one main form with its 3 subforms (main
form bound to table1, subform1 bound to table2, subform2 bound to table3,
subform3 bound to table4), primary key in table1 is foreign key in tables 2,
3, and 4 (primary key is AutoNumber, and foreign keys are Long Integer),
tables 2, 3, and 4 also have primary keys, which are also AutoNumber.

Any ideas why 2 new problems?

Thank you for the help you have already given!

--
2nd_Stage_User


Marshall Barton said:
When setting the focus to a control in a subform, you should
first set the forcus to the subform control.

Private Sub PageID_Exit(Cancel As Integer)
With Forms![BM_DataEntry]![SubjectHead_Subform]
.Setfocus
.Form![SubjectID].SetFocus
End With
End Sub
--
Marsh
MVP [MS Access]


2nd_Stage_User said:
My setfocus code is not working.

There are 4 pieces ... 1 piece for On Exit property of "last field" in Main
Form ... 1 piece for On Exit property of "last field" in 1st Subform ... 1
piece for On Exit property of "last field" in 2nd Subform ... 1 piece for On
Exit property of "last field" in 3rd Subform.

Code is reproduced at bottom. Can anybody see what's wrong?

My Goal ... Tab thru all fields on Form. Form consists of Main Form with 3
Subforms. (The Main Form has a few fields, and each Subform has a few
fields.)

Problem #1 ... When I attempt to Tab from "last field" in 1st Subform to
"first field" in 2nd Subform, the cursor does "not" move to 2nd Subform.
Instead, it moves back to "first field" of 1st Subform.

Problem #2 ... When I attempt to Tab from "last field" in 2nd Subform to
"first field" in 3rd Subform, the cursor does "not" move to 3rd Subform.
Instead, it moves back to "first field" of 2nd Subform.

Exception to Problems ... When I Tab from "last field" in Main Form to
"first field" in 1st Subform, the Tab works. Likewise, when I Tab from "last
field" in 3rd Subform to "first field" in Main Form, the Tab works.

For Code Reference ... what follows are names of Main Form, Subforms, and
fields:

Main Form = BM_DataEntry ... first field = PageID ... last field = Link
1st Subform = Details_Subform ... first field = DetailID ... last field =
PageID
2nd Subform = SubjectHead_Subform ... first field = SubjectID ... last field
= PageID
3rd Subform = Author_Subform ... first field = AuthorID ... last field =
PageID

CODE ...

1.) Code for Tab from "last field" in Main Form to "first field" in 1st
Subform:

Private Sub Link_Exit(Cancel As Integer)
Forms![BM_DataEntry]![Details_Subform].Form![DetailID].SetFocus
End Sub

2.) Code for Tab from "last field" in 1st Subform to "first field" in 2nd
Subform:

Private Sub PageID_Exit(Cancel As Integer)
Forms![BM_DataEntry]![SubjectHead_Subform].Form![SubjectID].SetFocus
End Sub

3.) Code for Tab from "last field" in 2nd Subform to "first field" in 3rd
Subform:

Private Sub PageID_Exit(Cancel As Integer)
Forms![BM_DataEntry]![Author_Subform].Form![AuthorID].SetFocus
End Sub

4.) Code for Tab from "last field" in 3rd Subform to "first field" in Main
Subform:

Private Sub PageID_Exit(Cancel As Integer)
Forms![BM_DataEntry]![PageID].SetFocus
End Sub
 
M

Marshall Barton

2nd_Stage_User said:
With your help, I can now advance thru each field in Main Form, and its 3
Subforms.

However, two new problems have occurred!

Problem #1 ... When I move out of Subform1 and into Subform2, the record
count for Subform1 changes to Record2. Yet, I haven't finished data entry
for Record1, as data entry into Subform2 and Subform3 has not yet occurred.

Problem #2 ... When I proceed to complete data entry of Subform2 and
Subform3 (for Record1) and close, and then open the Main Form, all entered
data is present, and the record count of Main Form, Subform1, Subform2, and
Subform3 is at Record1. However, as I enter Record2 data into Main Form and
Subforms, the record count remains at Record1. Effectively, Record2
overwrites Record1.

My Database Design ... 4 tables, one main form with its 3 subforms (main
form bound to table1, subform1 bound to table2, subform2 bound to table3,
subform3 bound to table4), primary key in table1 is foreign key in tables 2,
3, and 4 (primary key is AutoNumber, and foreign keys are Long Integer),
tables 2, 3, and 4 also have primary keys, which are also AutoNumber.


I'm not sure how that could be happening. Maybe you're
using the wrong event or the form's Cycle property is
causing it. All that may not matter because it sounds like
you might also have a flaw in your thinking (or problem
description).

A mainform record is "complete" and saved when it loses the
focus to a subform. Same for each subform losing the focus
to either the main form or another subform. Make sure those
facts are consistent with your form design/expectations
before digging too deep into fixing something that may not
be the right design.
 
G

Guest

Thanks again for your help!

My knowledge and skills are at a very early stage. (Maybe you could call me
an intermediate beginner.)

Regarding the "design" issue, my goal was to have a "single" data entry Form
for "convenient" inputting of data into 4 tables (Main, Details, Subject, and
Author).

How is a "design" that accomplishes this goal, different from what I've
designed? If the design needs to be different from what I designed, please,
would you at least say what the "outline" of this different design would be?
(The accomplishment of this "design goal" sure seems like it should be
do-able! My design is repeated below.)

"My Database Design ... 4 tables, one main form with its 3 subforms (main
form bound to table1, subform1 bound to table2, subform2 bound to table3,
subform3 bound to table4), primary key in table1 is foreign key in tables 2,
3, and 4 (primary key is AutoNumber, and foreign keys are Long Integer),
tables 2, 3, and 4 also have primary keys, which are also AutoNumber. "
 
M

Marshall Barton

2nd_Stage_User said:
My knowledge and skills are at a very early stage. (Maybe you could call me
an intermediate beginner.)

Regarding the "design" issue, my goal was to have a "single" data entry Form
for "convenient" inputting of data into 4 tables (Main, Details, Subject, and
Author).

How is a "design" that accomplishes this goal, different from what I've
designed? If the design needs to be different from what I designed, please,
would you at least say what the "outline" of this different design would be?
(The accomplishment of this "design goal" sure seems like it should be
do-able! My design is repeated below.)

"My Database Design ... 4 tables, one main form with its 3 subforms (main
form bound to table1, subform1 bound to table2, subform2 bound to table3,
subform3 bound to table4), primary key in table1 is foreign key in tables 2,
3, and 4 (primary key is AutoNumber, and foreign keys are Long Integer),
tables 2, 3, and 4 also have primary keys, which are also AutoNumber. "


That sounds good. The issue I had was when you said " I
haven't finished data entry for Record1, as data entry into
Subform2 and Subform3 has not yet occurred." To which, I
said that as far as Access is concerned, the data entry in
the main form is complete and the record is saved BEFORE you
can enter anything in any subform. As long as you
understand that the main form record is saved at that time,
your design is OK.

Moving on, check that each subform's Link Master property
is set to table1's primary key field and the Link Child
property is set to table 2, 3 and 4's foreign key
respectively.

Another thing to try is to set the main form's Cycle
property to Current Record.

If you've already done that and it didn't help, then try a
different tack. Add an unbound text box to the main form's
detail section and make it the last control in the Tab
Order. Then move your code from the control where it is now
to this "extra" text box's GotFocus event. If this works,
set the new text box's Height/Width to 0 so you can't see
it.
 
G

Guest

Thanks for all of your input.

Yes, I've definitely got it now: at end of data entry into Main Form, and
entrance into Subform1, Record1 is complete for Main Form (and, that this
"record completion" fact is also true for movement out of one subform and
into another subform). Thanks.

I'm glad you didn't stop at that point in your reply, as my current problems
aren't related to that issue. Everything that came after that point will go
a long way toward helping me to solve the problems that I described in my 2nd
post, in this thread.

I'm at work, so I can't yet try the things you've pointed out. I'll try
them when I get home. I'll let you know. Thanks again!
 

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