Screen.NextControl

N

Nat Vascular

Thanks for all your help in advance.....

I know there is a way to find out what the previous control is by using
Screen.PreviousControl. But is there a way to know what control you are
going to?

I have a situation where when a user leaves a control, either via mouse
click or the tab key, I would like to use the Exit or LostFocus property to
test where the focus is going and take some actions based on where they are
going. I looked everywhere and can't seem to find a way to know where the
focus is going. Access certainly knows where it is going, can I find out
where?

Thanks again!
 
F

fredg

Thanks for all your help in advance.....

I know there is a way to find out what the previous control is by using
Screen.PreviousControl. But is there a way to know what control you are
going to?

I have a situation where when a user leaves a control, either via mouse
click or the tab key, I would like to use the Exit or LostFocus property to
test where the focus is going and take some actions based on where they are
going. I looked everywhere and can't seem to find a way to know where the
focus is going. Access certainly knows where it is going, can I find out
where?

Thanks again!

You can find the next control in the tab order, but this will not
accurately determine what the next control will be if you use the
cursor, as the user can click in any other control at will.

Code the control's Exit event:

Dim intX As Integer
Dim ctl As Control
Dim prp As Property
intX = Me.ActiveControl.TabIndex
For Each ctl In Me.Controls
For Each prp In ctl.Properties
If prp.Name = "TabIndex" Then
If prp.Value = intX + 1 Then
MsgBox "Going to " & ctl.Name
End If
End If
Next prp
Next ctl

I would use a control's Enter event to determine where it came from.
Much simpler.

MsgBox "I arrived here from " & Screen.PreviousControl.Name
 
T

TonyT

Hi Nat,

I'm afraid there isn't a way to determine the next control, you have trap
the keycode and the mousedown events if you need to find where the user is
trying to go next, or force them in other ways......using the OnExit or
AfterUpdate events to set the next 'SetFocus' control.

TonyT..
 
K

Klatuu

The only way Access can even guess is to use each control's TabIndex and
TabStop properties. The TabStop determines whether a tab stops at this
control or not. The Tabindex determines the order. The first control on a
form will have a TabIndex of 0.

So, you could create an array, spin through all the controls on the form and
add those with a TabStop of True to the element in the array corresponding to
the TabIndex. Then to know what the next control is, you could use the
tabindex of the current control to lookup the name of the next control in the
array.

But, there is absolutely no point to doing this. A user can click on any
control, close the form, close the app, shut down the computer, etc. So how
do expect Access to guess where the user is going? Can't do it. Access will
only know where the focus arrived. The GotFocus event of any control can be
used to determine that.

But all that aside, and just out of curioosity, what did you have in mind
doing with the information on where the focus is going?
 
Top