473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Changing focus to a control on a different form

1,271 Expert 1GB
I'm having trouble changing the focus from form to form.

I've got a big form with two smaller forms. The main form takes the left 1/3 of the screen, subform1 the upper right, and subform2 the lower right portion of the screen. I want the user to be able to advance to subform1 with a control/M and to subform2 with a control/B keystroke.

I used this code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  2.  
  3. ' control/M will set the focus to the packages
  4. If KeyCode = vbKeyM And vbKeyControl Then
  5.     'Forms!frm_OEShippingSelectCustomer!fsub_OEShippingProduct.
  6.     With Forms!frm_OEShippingSelectCustomer!fsub_OEShippingProduct
  7.         !txtQtyShipped.SetFocus
  8.         !txtQtyShipped = 99  ' just to see if anything happened
  9.     End With
  10.  
  11.     KeyCode = 0
  12. End If
  13.  
  14. ' CONTROL/B will load the form for boxes/packages
  15. If KeyCode = vbKeyB And vbKeyControl Then
  16.     Forms!frm_OEShippingSelectCustomer!fsub_OEShippingProduct.Form!!txtWeight.SetFocus
  17.     KeyCode = 0
  18. End If
  19.  
  20. End Sub
  21.  
I want to end up with the focus on a control in the proper subform. But I keep ending up still on the main form. The "99" is showing up on the control txtQtyShipped, so I can see that it is executing the code.

How do I get parked on the proper form after my control keystroke?

Thanks,
Jim
Dec 26 '07 #1
3 8516
FishVal
2,653 Expert 2GB
Hi, Jim.

The following is from Access help.
You can use the SetFocus method to move the focus to a subform, which is a type of control. You can also move the focus to a control on a subform by using the SetFocus method twice, moving the focus first to the subform and then to the control on the subform.
So the code will look like this.
Expand|Select|Wrap|Line Numbers
  1. With Forms!frm_OEShippingSelectCustomer!fsub_OEShippingProduct
  2.     .SetFocus
  3.     !txtQtyShipped.SetFocus
  4. End With
  5.  
Regards,
Fish
Dec 26 '07 #2
yeah you gotta do it in two steps, like fish said.

Another example using more with blocks - lol
Expand|Select|Wrap|Line Numbers
  1.  
  2. With Me
  3.   With .fsub_OEShipping
  4.     .SetFocus
  5.     With .Form
  6.       With .txtQtyShipped
  7.         .SetFocus
  8.       End With
  9.     End With
  10.   End With
  11. End With
  12.  
  13.  
As you can see you are trying to reference and object that has a nesting level 4 deep.

The best I come up with a two liner:
Expand|Select|Wrap|Line Numbers
  1. Me.Form!fsub_OEShipping.SetFocus
  2. Me.Form!fsub_OEShipping.Form!txtQtyShipped.SetFocus
hth

Alan ";0)
Dec 26 '07 #3
jaxjagfan
254 Expert 100+
If both of your subforms are based on the same table as their data source (your choices on which subform to pick seems to be based on package or box - basically package size). I would enable or disable controls within a single subform - if package enable QTY and disable weight and viceversa for box. Make it less for end users to have to remember. A little more development work but a better user experience.
Dec 26 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: tshad | last post by:
I have a date validation function that I want to stay at the object I am validating if there is a Validation error, but it always goes to the next object. The Javascript: function...
2
by: aaj | last post by:
Hi all I have a small but rather annoying problem with continuos forms, and am wondering if anyone can suggest a method of getting over it. The front end is Access 2002 with the BE being SQL...
17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
2
by: Elliot M. Rodriguez | last post by:
Is it possible to change a control's focus at runtime? I'm sure you can.... I have a form with 2 textbox controls that cause postbacks. They are located in the middle of my form. When a...
12
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function...
4
by: Aung Thu | last post by:
Hi, there! I want to set focus on a control, of which TabIndex is not the first, when a form is loaded. In the form's load event, I have used Control.Focus() but it doesn't not work. The focus...
4
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I...
4
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I...
3
by: nano2k | last post by:
Each form has its ActiveControl property, but no ActiveControlChanged event to signal that the active control has changed (like ParentChanged event). I tried to trick the form by declaring this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.