Setfocus problem

  • Thread starter Thread starter Random
  • Start date Start date
R

Random

Hi,

I'm having a strange problem with SetFocus in my application.
Basically I have a wizard which guides the user through a process to
set up a new account. The UI is a form with 2 subform controls called
'subform' and 'footer'. The subforms SourceObject changes whenever the
user presses Next or Previous (command buttons located on the footer
subform). The wizard is a 5 step process. The problem I'm having is
that when pressing next from step 1 to step 2, I cannot get the cursor
to appear on the form. The only way I can continue is to do a mouse
click anywhere on the form and the cursor then appears in the correct
control.

The code I am using to set the focus is as follows
frm.SourceObject = "frmStep02":
frm.SetFocus
frm!subform.SetFocus
frm!subform.Form.Controls("txtName").SetFocus

Where frm is a reference to the parent form.

Although the code is somewhat more involved than that shown, I am
convinced I am doing nothing wrong. One reason for this belief is that
if I click 'next' to go to step 3, the cursor appears correctly on the
next page. The code is almost identical.

frm.SourceObject = "frmStep03":
frm.SetFocus
frm!subform.SetFocus
frm!subform.Form.Controls("cboProduct").SetFocus

If I now click 'Previous' on this page, the wizard retruns to step 2
(running the same code as shown previously), but this time the cursor
appears as expected!!

So to summarise:
a) I move from step 1 to step 2 and the cursor will not appear on the
screen. To get the cursor I have to do a mouse click anywhere on the
screen, and the cursor then appears in the correct control.
b) If I move from step 2 to step 3, the cursor appears correctly.
c) If I move back from step 3 to step 2 the cursor appears correctly.

I have looked through some previous posts, and found a thread from
2002, where the person posing the question appeared to have the same
problem. Unfortunately, no-one seemed to grasp the issue at hand
(which I can understand as it is not easy to describe or replicate) and
so there was no solution. I'm thinking this is one of those quirky
things that Access does from time to time, but so far I have not been
able to find a work around.

If anyone has had the same problem I'd be interested in how you worked
around it.

TIA
Steve.
 
Say that a form F1 has a subform control named SF. SF contains a form
F2 which contains a control named BLAH.

To set the focus to BLAH, from code within F1:

me![SF].setfocus
me![SF].form![BLAH].setfocus

Note:
- you do NOT use the name of F2;
- you must set the focus to the subform control first, & then to the
field of the form within that subform control.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Back
Top