Focus jumps a control

T

TonyT

I have the following code in the keydown event of a subform control;

If Not Shift = 1 Then
If KeyCode = 9 Then
Me.Parent!lstCont.SetFocus
End If
End If

I have similar in other db's working fine, but in this one whichever control
in the parent form I set the focus to, the focus jumps to the following
control in the tab order. ie, lstCont is TabIndex 24, the focus flashes very
briefly on lstCont and then moves to lstDel TabIndex 25. If I change the
above code to Me.Parent!lseDel.SetFocus, the focus then goes to the next
control (Index 26).

I've decompiled/recompiled, imported into a new db, compacted and still it
does it. Neither form have any coding that could interfere with the setfocus
command & debug print always says activecontrol is lstDel or whatever I set
the focus too, even though it isn't.

hope that all makes sense.
 
G

Graham Mandeno

Hi Tony

Try setting KeyCode = 0 just before the SetFocus.

I think what is happening is you are setting focus to the main form control,
but because KeyCode is still 9, the tab action is still acted upon and focus
moves to the next control.

Also, I recommend you use the built-in constants as they make the code
easier to follow:

If Shift <> acShiftMask Then
If KeyCode = vbKeyTab Then
KeyCode = 0
Me.Parent!lstCont.SetFocus
End If
End If
 
T

TonyT

Thanks Graham,

That sorted it perfectly.

Graham Mandeno said:
Hi Tony

Try setting KeyCode = 0 just before the SetFocus.

I think what is happening is you are setting focus to the main form control,
but because KeyCode is still 9, the tab action is still acted upon and focus
moves to the next control.

Also, I recommend you use the built-in constants as they make the code
easier to follow:

If Shift <> acShiftMask Then
If KeyCode = vbKeyTab Then
KeyCode = 0
Me.Parent!lstCont.SetFocus
End If
End If

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

TonyT said:
I have the following code in the keydown event of a subform control;

If Not Shift = 1 Then
If KeyCode = 9 Then
Me.Parent!lstCont.SetFocus
End If
End If

I have similar in other db's working fine, but in this one whichever
control
in the parent form I set the focus to, the focus jumps to the following
control in the tab order. ie, lstCont is TabIndex 24, the focus flashes
very
briefly on lstCont and then moves to lstDel TabIndex 25. If I change the
above code to Me.Parent!lseDel.SetFocus, the focus then goes to the next
control (Index 26).

I've decompiled/recompiled, imported into a new db, compacted and still it
does it. Neither form have any coding that could interfere with the
setfocus
command & debug print always says activecontrol is lstDel or whatever I
set
the focus too, even though it isn't.

hope that all makes sense.
 

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