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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tabbing Problem when using subforms.

Status
Not open for further replies.

davegillian

Programmer
Jul 25, 2007
10
GB
Hi,

I've got a form that is quite long (2-3 screens). The controls on the form continue down on progressively nested subforms giving the illusion to the user that they're just inputting on one single form.

The problem I have is that as you tab through all the fields once you get beyond the controls placed on the main form the cursor disappears off screen and the form no longer scrolls with it.

This is really annoying as it slows down inputting significantly when you have to go to your mouse to scroll the page down every few fields.

Is there any way of getting around this problem...some kind of code that positions the form on screen so that the control with focus is at the top or something?

Any help appreciated as this one's driving me mad!!!

Cheers,

Dave
 
Have you tried setting focus to the next control from the one you are leaving (ie the last visible control on the form as you see it). In the afterupdate of say control 12, put eg. me.textbox13.setfocus
 
Cheers for the suggestion but yeah I've tried this. The problem isn't getting the controls in the subform to take focus. The cursor moves through the fields just as I wanted it to.

The problem is that once the form has scrolled down so that all controls on the main form are out of sight the form no longer scrolls. Tabbing continues to give focus to each control but you can't see what field you are supposed to be inputting or what you've typed unless you manually scroll the form with the scroll bar.

I'm not sure if I'm explaining this well or not but imagine a form 45 cm in height and a monitor that displays 15cm of height at any one time. From 15cm to 45cm on the main form is a subform and nested in this subform from 15cm-30cm (or 30cm-45cm in terms of the main form) is another subform.

Tabbing takes you through the fields located on the main form, then moves you through the fields on the first subform. Once you tab onto the first field in the 2nd subform the entire form has scrolled far enough that 15cm is at the top of the screen and the controls on the main form are all out of sight to the top. At this point the cursor moves through the fields in the 2nd subform but as the form no longer scrolls down you're unable to see what's happening.

You would expect the form to keep scrolling until the bottom of the form (45cm) is displayed at the bottom of your screen.

HELP!
 
You would expect the form to keep scrolling
Why would you expect that as it has no longer focus ...
 
What happens if you set focus to a textbox near the bottom of your next page/part of the form, and on its getting focus property set a new focus to the control at the top of the page? Make the textbox hidden, ie forecolor/backcolor same as form backcolour, border transparent, and when/if it works later set its height/width to zero so you don't see the cursor blinking at any time. It's only an idea, you will have to play with it.
 
PHV:

I would expect that the program Microsoft Access as a whole would display the point of focus wherever it was on a form or subform. As the subform is part of the overall form it could be argued that it still does have focus - and either way what's the point of having a subform if it isn't going to be displayed on screen?!

Anyway that discussion is irrelevant as it doesn't help me see what I want to see on screen!

ZOR:

Thanks for the suggestion. I will have a play around with that tomorrow. I've got a feeling I had trouble setting focus from a subform textbox back to a textbox in the main form previously but that might just be my lack of coding ability! I do have an exit button at the very bottom on the main form and you can set focus to that no problem.

I'll post news of my success or problems!

Cheers for the help guys!
 
Ok I've tried setting focus to a textbox at the bottom and it doesn't work...runtime error 2110.

Here's a simplified version of my form...with "---" representing the start of a form/subform and "***" representing the end of a form/subform.

--------
MainForm

Control1
Control2
Control3

--------
Subform1

Control1
Control2
Control3

--------
Subform2

Control1
Control2
Control3
********
********
Control4
********

Imagine my monitor can only display 5 controls at once. Tabbing (with it set up in order going down the form) gets me to Control 2 on Subform2 (therefore controls1,2&3 on Mainform just off screen and the very top of subform1 being at the very top of the screen). Another hit of the tab button puts focus on control 3 but the form doesn't move so I can no longer see the cursor.

I've tried adding an event proceedure for exit on control 3 of mainform to setfocus. This works as expected for all controls on subform 1 and 1,2&3 on mainform but all others cause the following problems:

*Mainform control4 - Run-time Error 2110 - Cannot set focus to control 4.
*Subform 2 - Focus goes to control1 on subform 1
 
I tried making a very long form. At the top I put a textbox, so when the form was opened, focus went to that text bob. Alongside the textbox I put a command button. In the click event of the command button I set focus to another textbox at the very bottom of my form. I ran it, clicked the button, and it set focus/moved the form to show the form part where the textbox at the bottom was at the bottom of my form and it had focus.

It might be a good idea if you put your code in this thread to show how you are addressing a control on a form, and a control on a subform.

Another way you could have done this would have been to use a tab control. You could have kept the tabs visible while designing your page, and then hidden them and showed pages in whatever order you wanted programatically. The only thing I don't like about a tab control is you cannot change the backcolour, and don't try putting labels on them as they flicker badly when you run your mouse over them. Use textboxes instead with them being ddisabled and locked.
 
I could use a tab control but I don't particularly like them and I think they're messy.

As for the code. The code I'm using to set focus is sound as it works on all my forms but to be honest most of the time I don't use code to move between the control just the tab button.

The problem definately lies with Access not moving forms when all the controls on screen are located on a subform. It then carries on moving focus but not the screen with it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top