SetFocus not working when move from one subform to another

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have 1 Main form with more than 20 subforms. I have created a code below
on every the On Exit event of every subform to move to the next field of the
next subform.

Private Sub Corporate_Objectives_Exit(Cancel As Integer)
Me.Parent.SetFocus
Me.Parent.RSF017_BranchObjectives.SetFocus
Me.Parent.RSF017_BranchObjectives.Form.Branch_Objectives.SetFocus
End Sub

It works fine when moving from subform to the next on the current record.
But when I tried to create a new record the error message coming up as below.

Run Time error "2110"
Microsoft Access can't move the focus to the control of the "subform name"

Also another error with "Automation error".

I would appreciate it could you please tell me why I have this problem.

I don't have this problem when there are only 5 subforms, but now I have 20
subforms. Will the number of subforms cause the error.

Also how to move out of the last subform to the main form to create a new
record?

Thanks
Hong
 
Hi

I have 1 Main form with more than 20 subforms. I have created a code below
on every the On Exit event of every subform to move to the next field of the
next subform.

Private Sub Corporate_Objectives_Exit(Cancel As Integer)
Me.Parent.SetFocus
Me.Parent.RSF017_BranchObjectives.SetFocus
Me.Parent.RSF017_BranchObjectives.Form.Branch_Objectives.SetFocus
End Sub

It works fine when moving from subform to the next on the current record.
But when I tried to create a new record the error message coming up as below.

Run Time error "2110"
Microsoft Access can't move the focus to the control of the "subform name"

Also another error with "Automation error".

I would appreciate it could you please tell me why I have this problem.

I don't have this problem when there are only 5 subforms, but now I have 20
subforms. Will the number of subforms cause the error.

Also how to move out of the last subform to the main form to create a new
record?

Whoa. Do you have a different subform FOR EACH BRANCH?

Why so many subforms? This will make the form extremely "heavy" and slow to
load. Not sure whether it's causing this error or not though, the code looks
valid.

John W. Vinson [MVP]
 
Hi John

I am developing the database on request and the user want to track the
history of every single fields on the form, that's why I have a table for
every single field.

Any idea to fix my code or is there other way to track the changes on the
form.
Hong
 
Hi John

I am developing the database on request and the user want to track the
history of every single fields on the form, that's why I have a table for
every single field.

"A Table for EVERY SINGLE FIELD!?"

Ouch. No, that is certainly not how I'd do it.

Any idea to fix my code or is there other way to track the changes on the
form.

A "change log" table is pretty common. There are at least two ways to do this.
One would be to have an archive table, with all of the fields of your existing
table plus two more - a ChangedDate date/time field and an ID of the person
doing the changing. In the Form's BeforeUpdate event you would add a record to
this table, copying each bound control's PreviousValue into it.

Or if you want to track each change to each field individually, you could have
a log table with fields Fieldname, DateChanged, OldValue, NewValue, and
ChangedBy; add a record to this table in the BeforeUpdate event of each bound
control on the form.


John W. Vinson [MVP]
 
Thanks John,

Could you please see if anything can be done to fix my above code.

The above codes works only to move from one subform to another if there is
already a record, and the error occurs only when I create a NEW record .

My code was on the last field of the first subform to the second subform.
And I have disable all the codes for the other subform. which means that I
only have 1 Main form with 2 subforms.

Thank you very much for your time on this.
Hong
 
Back
Top