Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get cursor to tab into a subform

Status
Not open for further replies.

tpolony

Programmer
Aug 9, 2003
17
US
When I try to tab from the main form into the first field of a subform, the cursor gets stuck in the last field before the subform. It won't enter the subform, even when I try to click on the field manually. The fields are all enabled, all set with tabstop = yes, and the and the tabstops are numbered properly. The relationship with the parent object seems OK, there is an ID field linking the two properly.

When this happened on another form, it was because the first field in the subform was disabled (with no tab stop), and Access didn't know what to do. Renumbering the disabled field so it was not the first tab stop in the subform solved that problem. But it's not working here. HELP, I'm supposed to deliver this thing tomorrow, and nothing works!

 
This is a very good question...something I didn't figure out how to do until recently. What you're gonna need to do is write some VBA code for the OnLostFocus event of the last control that you want to have the focus. The code will look something like this:

[Forms]![frmMain]![frmSub].SetFocus
DoCmd.GoToControl "Control"

FrmSub is the subform you want to move the cursor to and Control is the name of the control that you want to tab to. Any questions, please let me know.

TOTCOM11
 
I'm getting closer... When trying to set focus on the subform, I get runtime error 2110 saying it couldn't move focus to my subform. When I ignored the error twice (telling debugger to end), it goes to the field. So I added code to trap error 2110. Then I get a message that the field I want to go to doesn't exist (it's spelled correctly).

Here's my syntax, all in the previous field's OnLostFocus event, am I doing something wrong?

Forms!BondDetail!BondInterestRateSubform.SetFocus
DoCmd.GoToControl "InterestRateDate"

InterestRateDate is the subform field. Do I have to prefix it somehow? I tried the full path:
Forms!BondDetail...InterestRateDate.Name etc, no success. I also tried putting the GoToControl part in the subform's OnGotFocus event, but that never got triggered, and instead tabbed back to the top of the page. So close to working, I can feel it. Any futher advice, greatly appreciated.
 
Did you make sure that the tab order of your main form includes the subform you want to go to? The subform should be the tab stop right after the last field on the main form.

Also, "InterestRateDate" may not have a prefix. The subform must have focus, and once it does, only then can it find the control. Sometimes there is something that you are doing to take the focus away from the subform, even if you set the focus to it. I would check all of your code to make sure there isn't anything taking the focus away after you set the focus to your subform. This can be a very frustrating process, as I know I've done this many times.

My bottom line advice would be to make sure your subform tab stop comes after the last field that is to be tabbed on the main form. If it is not in the correct order, try tabbing without the additional code. If that doesn't work, try it with the additional code. If that still doesn't work, let me know via this thread.

Hope this helps!
TOTCOM11
 
As it was "leaving" the main form, it was calling the main form's BeforeUpdate method, so it lost focus. Commenting it out solved that problem.

But now I have a new problem. I NEED that BeforeUpdate method. I'm trying to figure out some hack-around, if you have any further ideas, please advise. Thanks for everything so far.
 
What are you trying to accomplish in the BeforeUpdate method?
 
My form has tabs, and it updates indiscriminately every time it changes tabs, without using any of my specialized code in my Save method (also, a Save is not always desirable). So I set a flag to tell BeforeUpdate if the update is OK to do or not. It just says "Cancel = cancelUpdate", where cancelUpdate is the flag that I turn on and off to indicate if the update is OK to do (hack, hack, hack!).
 
Related REALLY Annoying Tab Order Question

I have various Tabbed Pages (tab as in file folder looking things, not the <tab> key). I just spent 15 of the most frustrating minutes of my life trying to get the tab order right, only to discover that when you type a number in, Access changes it! How this is a &quot;feature&quot; I don't know. This renders tab orders basically useless unless I write some code for each control, which is...annoying.

Any help appreciated. Great post, by the way TotCom.
 
Ogart,

Are you saying that the tabbing within each tab is wrong? Or are you saying tabbing to other tabs is wrong once you are done tabbing through the current page?

tpolony,

What do you WANT the functionality of your form to be? I don't understand this save method. If you could, lay out what your form does, and what you want it to do in as much detail as you feel is needed.
 
Ogart, you can go to View/Tab Order in form design, tell it to AutoOrder to get it in the basic order indicated by the field placement on the screen, then modify the auto-ordered fields manually using drag/drop. I had the same problem. My recommendation is to do all of your development and not worry about tab order until the very end, or else you will end up having to re-order the tabs multiple times, and it's a pain.

OK, after analyzing this some more, the BeforeUpdate method, which will cancel the update if the flag is set to true, is causing this whole problem.

I want to tab into the subform no matter what. BUT, when the main form loses focus, if I've changed any field before trying to go to subform, Access tries to do its handy-dandy automatic save. I set up the BeforeUpdate to cancel any saves that DO NOT go through an authorized channel (like clicking on the Save button and calling my Save method) because the automatic save feature causes inconsistency in my data (it only saves the record, not any of the unbound fields I have to manually save along with it, etc, plus it saves at inappropriate times -- like going to the subform!). So that's why my main form has this &quot;BeforeUpdate cancel&quot; concept.

When trying to tab to subform, it can't focus on the subform, because the main form &quot;lost focus&quot; tries to do the automatic update, and it goes to a line of code that checks my before update cancel flag. Because the focus has now shifted back to the main form, the subform loses focuses again and doesn't get re-activated. I don't see how I can code around this.

Seems to me if the subform's &quot;gotfocus&quot; is wanting to run, the main form's &quot;lost focus&quot; should simply complete and then continue on to the subform's got focus. But instead, my main form's lost focus activities are causing the subform's got focus&quot; to basically abort. This seems like an Access &quot;undocumented feature&quot; (bug). Am I making sense?

And yet I can't remove this before update event, I absolutely must have it. I can't win either way, unless someone can think of some additional hack I can do to fix this.

Since the issue seems to be this got focus/lost focus/before update sequence more than anything now, do you think I should re-post this message with the question: Subform's GotFocus event being aborted by Main Form's BeforeUpdate event. How to work around? Now that I tried this tip from you, TOTCOM11, it's helping me to drill down into what the real issue is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top