473,903 Members | 3,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I set focus from one subform to another?

Seth Schrock
2,965 Recognized Expert Specialist
I'm trying to set the focus from one subform to a control on another subform that is on the same parent form. Currently I have:

Expand|Select|Wrap|Line Numbers
  1. Forms!frmCustomersfrmFileTypes!FileName.SetFocus
but it doesn't work. I'm guessing that is because I'm starting from another subform because I've used this before to go from the parent form to the subform and it worked. I thought I could set the focus to the parent form and then use the above code but that didn't work either.
Dec 2 '11
19 11954
NeoPa
32,584 Recognized Expert Moderator MVP
I'm not sure I know the answer to this off the top of my head Seth (and I don't have anything to play with and test).

I can't promise anything, but if you attach your sanitised database (Attach Database (or other work)) I'll look at it for you and see if I can determine what's going wrong.
Dec 7 '11 #11
sierra7
446 Recognized Expert Contributor
Hi
I think you have to do this in stages. First move the focus up to the Parent, then to the sub-form control, then finally to the required fieldname.
Expand|Select|Wrap|Line Numbers
  1. Me.Parent.SetFocus
  2. Me![SubformName].SetFocus
  3. Me![SubformName].Form![FieldName].SetFocus
  4.  
A bit tedious but something similar happens when you are dealing with multiple subforms in Design mode, you have to click on the parent container before you can select an element within it.
S7
Dec 7 '11 #12
Seth Schrock
2,965 Recognized Expert Specialist
@sierra7 I just tried your code and it came back with a "{database name} can't find the field 'sfrmFileTypes' referred to in your expression." error message in the second line of code. I tried putting
Expand|Select|Wrap|Line Numbers
  1. Me!frmCustomer.Form!sfrmFileTypes.SetFocus
but all that did was make the error say "can't find field 'frmCustomer'".

@NeoPa I will try to get you the sample database here shortly. I'll include some sample data as the real data is confidential.
Dec 7 '11 #13
Seth Schrock
2,965 Recognized Expert Specialist
Okay... Here is the sample database in .mdb (not .accdb). I tested it after creating the new sample and the problem still exists. You will notice empty combo boxes and tabs, but don't worry about them. I just didn't include the extra forms and tables.
Attached Files
File Type: zip Seths Database Test.zip (85.1 KB, 229 views)
Dec 7 '11 #14
NeoPa
32,584 Recognized Expert Moderator MVP
What do I do to get your code to attempt to execute, and where exactly is this code found?

Probably a dumb question, but it's late and I'm tired ;-D
Dec 8 '11 #15
Seth Schrock
2,965 Recognized Expert Specialist
The code is found in sfrmEmail in the Email control's OnChange event. To trigger the code, open frmCustomer. In the tabs, select a blank file under Regular 1 (as if you just finished entering the Regular 1 record) and then try typing in an email address. Basically, I'm trying to keep an email address from getting assigned to a blank file.
Dec 8 '11 #16
sierra7
446 Recognized Expert Contributor
Hi Seth
You must do this in stages. What I missed was ALL the instructions are coming from the first sub-form so must be routed through the Parent
Expand|Select|Wrap|Line Numbers
  1. Me.Parent.SetFocus
  2. Me.Parent![sfrmFileTypes].SetFocus
  3. Me.Parent![sfrmFileTypes].Form![FileName].SetFocus
The above works
S7
Dec 8 '11 #17
NeoPa
32,584 Recognized Expert Moderator MVP
I cannot get the code to fire at all. In Datasheet mode (as it is) it just ignores any changes to the control :-( I tried in other modes too and no joy there either.

It does require a reference that I don't have, and I guess that must be the problem. I replaced it with the closest match I could find on my system, but the OnChange event simply never triggered (and I tried various different options to see if I could make it do so). It also wouldn't allow me to sign the project, so something wasn't quite right with it somewhere (on my system at least).

Sorry.
Dec 8 '11 #18
Seth Schrock
2,965 Recognized Expert Specialist
@sierra7 Thanks. It works perfectly.

@NeoPa I'm not sure why you couldn't get it to work. After I created the sample database, I tested it to make sure that the problem still existed and everything triggered like it was supposed to.
Dec 8 '11 #19
NeoPa
32,584 Recognized Expert Moderator MVP
I'm sure you did Seth. No criticism implied.

I suspect that the availability of the reference on your PC made it behave differently for you than for me.
Dec 8 '11 #20

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

Similar topics

2
1658
by: Stuart Wexler | last post by:
Hi, I was wondering if there is any way with onload that I can highlight (blue color) the select box field while simultaneously placing the mouse cursor or focus on a text box immediately below it? Thanks in advance. -Stu
17
3874
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 record to the subform (based on the value of the combo box) and requeries the subform control. I want the focus to return to the combo box on the main form when it's done, but I can't get it to do so if the user enters a value and presses Enter...
0
1177
by: Angel | last post by:
I have a Win application with two child windows (formX and formY) that are both opened when the application loads. formX has a multi-line textbox that I use to enter an address, and two button controls (one processes the address, the other clears the textbox). If I start working on this form (typing the address and processing it with one of the two buttons), everything works fine. If I then go to formY (to do something entirely different)...
0
1451
by: MattB | last post by:
I have a page with several user controls on it. Some of the UC's have multiple text boxes that get auto-populated via the OnTextChanged event. When this happens, I lose my focus (where the blinking cursor is). I have some SetFocus JavaScript that works from a page event, but I'm not sure what I'd need to change to make it work from within a UC and have it set focus to another control inside another UC. To complicate this further, I'd...
1
1647
by: Heather Crow | last post by:
I have a VS.NET 2003 Visual Basic form which keeps hanging. It does not appear to matter what textbox I am on. When trying to edit the field I cannot move focus from this field to another. Clicking buttons etc. does nothing and the focus remains with the field I had been editing. The text boxes are bound to a record in a SQL database.
1
1475
by: Bob | last post by:
There is an aspect of Windows design that I've always disagreed with, and that is its focus-switching behavior. I'll be typing something, and another application pops up a message box right in the middle of what I'm doing. Maybe I'll even hit enter for a line break and instead answer a yes/no dialogue that I didn't even get a chance to read. Or, perhaps I ctrl-click on a web link and go off to do something else while I wait for it to load....
8
51745
by: Tom | last post by:
I am using VB.NET to control another program. I have the program's window hwnd; however, I need to be able to set the focus to that other programs window so I can send it some keystrokes. I thought I could just use the SetFocus API, but I read somewhere that it will only work for programs running under that programs thread. Is this true? If so, how can I set focus to another program's window via VB.NET? Thanks. Tom
0
1790
by: hzgt9b | last post by:
Using VB .NET 2003, I am having problems with a windows application that I have written: Here's the situation. The application I created has a main form that has its TopMost property set to True (so that the form is always on top). During the execution of the application, a new process is created using "Process.Start(<some app>)". The problem is that after I start a new process, my main form no longer has focus, so all keyboard events are...
1
10829
by: massimo s. | last post by:
Hi, I would like to know if 1)there is a Python way to tell under which terminal process a Python command-line application is running 2)there is a Python way to tell the OS to give focus to another window. Solutions for Windows, Linux and OS X are welcome, even if OS-specific (of course general solutions are better, but I can kludge & check the platform).
1
3195
by: WackoZacho | last post by:
I've tried searching on Google and for other questions similar to mine, but all I get are results on how to use the LostFocus event or Deactivate, etc., but I'm under the impression each of these applies to controls on a form, or the actual form itself. What I need is a way to determine when my access database looses the focus entirely to another program in Windows, such as if I click on one of my access forms, MSAccess will have the focus. If I...
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11279
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7205
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4307
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.