Interesting, Sendkeys Workaround

  • Thread starter Thread starter Jimmy
  • Start date Start date
J

Jimmy

Hello,

Thank you very much for helping me.

Here is the short version of my challenge:

1. Currently, I have attached the following code to my
comboboxes on the OnClick event: Sendkeys "{TAB}", True
2. I did so because my users enjoy the focus moving
after they use the mouse to select an item in the combo
box.
3. I did so without realizing the known issue with
Sendkeys that causes the number lock to shut on and off.
4. My specific need is to delevop a technique to move
the focus to the next tab stop control on the OnClick
event.
5. My hope is to develop generic code that I can use
throughout the program so that I do not have to have
individual statements for all 388 comboboxes.

Here is the work that I have done so far:

1. I have attempted to use the Screen.ActiveControl
properties to identify the next control. Then, to
use .SetFocus or DoCmd.GotoControl to move to that
particular control. So far, no luck on identifying the
control name. (It is a shame that there is not a
Screen.ActiveControl.NextControl as there is a
Screen.ActiveControl.PreviousControl property.

2. I have attempted to use the Index number for the
ActiveControl to determine the next control. However,
the Indexes do not appear to have been created logically
on all of my forms.

Thank you for your assistance. Have a great day.

Jimmy
 
Jimmy,

The solution is a bit simpler actually if the OnClick is not
too early for the Value to settle in to the bound control.

Me!YourNextControlName.SetFocus

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
Jimmy,

I have a routine the purpose of which is to find the 'first' control on a
form.
It seemed that a quick hack should deliver what you're after.
And a quick hack is what it got - so check it carefully if you use it.

For the routine to work, you must have defined the form's TabOrder to follow
the sequence you require.

Good luck.
CD

' truly untested code
Public Function Next_Control_in_TabOrder(Frm As Form, Optional currCtrl As
Control = Nothing) As Control
'*******************************************
'Purpose: set focus to the first accessible control on a form (rev: after
currCtrl)
' ... to be selected, it must be
' a. an editable control
' b. in the detail section
' c. visible
' d. enabled
' e. lowest tab index (rev: after currCtrl)
'Author: Chas
'Date: april 11, 1999, (rev: Nov 07, 2003)
'Called by: General system use
'*******************************************

On Local Error Resume Next

Dim i%, j%, possTarget As Boolean, landed As Boolean, ctrl As Control
Dim n%
Set Next_Control_in_TabOrder = Nothing
Application.Echo 0
If (currCtrl Is Nothing) Then Set currCtrl = Frm.ActiveControl
i = currCtrl.TabIndex + 1 ' the tabindex value needed
landed = False
Do
j = 0 ' the control being examined
Do
If j >= Frm.Count Then Exit Do
Set ctrl = Frm(j)
possTarget = (ctrl.TabIndex = i) And (ctrl.Section = acDetail)
Do ' not a loop, just a glorified GoTo
If Err <> 0 Then Exit Do
If Not possTarget Then Exit Do
If ctrl.Visible = False Then Exit Do
If ctrl.Enabled = False Then Exit Do
ctrl.SetFocus
If Err <> 0 Then Exit Do ' ctrl can't take the focus
' we've found a possibility ...
' but if it's a subform inside a tabbed control
' ... we'd rather keep on looking
If ctrl.ControlType = acSubform Then Exit Do
If ctrl.ControlType <> acTabCtl Then
Set Next_Control_in_TabOrder = ctrl
landed = True
Exit Do
End If
' see if we can get to the 1st control in the tabbed page
n = 0
Do
If n >= Frm(j).Count Then Frm(j).SetFocus: Exit Do
Set ctrl = Frm(j).Controls(n)
If (ctrl.TabIndex = 0) Then
ctrl.SetFocus
If Err = 0 Then
Set Next_Control_in_TabOrder = ctrl
landed = True
Exit Do
End If
End If
n = n + 1
Loop
Exit Do
Loop ' end of GoTo sequence
Err.Clear
If landed Then Exit Do
j = j + 1
Loop
If landed Then Exit Do
' can't find a target at this TabOrder index, so bump it up
i = i + 1
If i >= Frm.Count Then Exit Do
Loop
Application.Echo -1
Set ctrl = Nothing
End Function
 
OK,

I see where you are going. Thank you very much.

I will give it a go. Check back later, and I will let
you know how I did.

Thx,

Jim
 
Jimmy said:
Hello,

Thank you very much for helping me.

Here is the short version of my challenge:

1. Currently, I have attached the following code to my
comboboxes on the OnClick event: Sendkeys "{TAB}", True
2. I did so because my users enjoy the focus moving
after they use the mouse to select an item in the combo
box.
3. I did so without realizing the known issue with
Sendkeys that causes the number lock to shut on and off.
4. My specific need is to delevop a technique to move
the focus to the next tab stop control on the OnClick
event.
5. My hope is to develop generic code that I can use
throughout the program so that I do not have to have
individual statements for all 388 comboboxes.

Here is the work that I have done so far:

1. I have attempted to use the Screen.ActiveControl
properties to identify the next control. Then, to
use .SetFocus or DoCmd.GotoControl to move to that
particular control. So far, no luck on identifying the
control name. (It is a shame that there is not a
Screen.ActiveControl.NextControl as there is a
Screen.ActiveControl.PreviousControl property.

2. I have attempted to use the Index number for the
ActiveControl to determine the next control. However,
the Indexes do not appear to have been created logically
on all of my forms.

Thank you for your assistance. Have a great day.

Jimmy

See my reply in the thread, "coding to cancel or go (tab) back to
previous text box in form", message-id
, in this newsgroup.
 
Although i really dislike the garbage control names that Access
generates (but, it has to do something) and almost always replace with
meaningful names, this could be a case for garbage names. If you named
your combos like this: cbo000, cbo001, ... Then you could parse the
current combo # (Right$(Screen.ActiveControl.Name, 3)), convert to an
Int, add 1, and convert back to a String (being sure to use 3 digits in
the format). Finally, SetFocus to that control name (something like
Controls(strName).SetFocus

I may have the wrong names above, but the concept should be OK.
-=-=
 
Dirk,

Thank you for your excellent suggestion. Elegant code
too. Very interesting thread.

This is the example I adopted.

Thx,

Jim
 
Back
Top