My Assistant
![]() ![]() |
|
|
Apr 10 2012, 05:12 PM
Post
#1
|
|
|
UtterAccess Member Posts: 43 |
I have a form contains a tab control. This tab control has 7 tabs ( 7 pages). Each page contains a subform.
When I am in the first page and hit the last control of this page. I use set focus to move to next tab (next page) first field. here is the code... Forms!frmentry.TabCtlEntry.Value = 1 Forms!frmentry.sfmREC.SetFocus Forms!frmentry.sfmREC.Form!comReview.SetFocus When it runs, it moves to next tab (next page) but not the field comReview. It sets focus to the field that follows comReview. I tried to use different ways to set the focus for each page when the subform is load, or is open, or is current. It doesn't work. Please help... Thanks MYC |
|
|
|
Apr 10 2012, 05:16 PM
Post
#2
|
|
|
UtterAccess VIP Posts: 1,857 From: BC, Canada |
Is there any event procedure code in the subform that might be taking the focus away from the control you wanted?
|
|
|
|
Apr 10 2012, 05:41 PM
Post
#3
|
|
|
UtterAccess Member Posts: 43 |
In the last control of the first subform (first page) I used the keydown event to check if it is tab key or return key entered. If it is, then set the focus to next tab (2nd page). I don't see any event after this.
|
|
|
|
Apr 10 2012, 06:44 PM
Post
#4
|
|
|
UtterAccess VIP Posts: 1,857 From: BC, Canada |
In the last control of the first subform (first page) I used the keydown event to check if it is tab key or return key entered. If it is, then set the focus to next tab (2nd page). I don't see any event after this. I am wondering then if it might be a timing issue. Try putting a call to DoEvents before setting focus to comReview and see if that makes a difference. Mike |
|
|
|
Apr 10 2012, 06:55 PM
Post
#5
|
|
|
UtterAccess Member Posts: 43 |
I thought about the timing too so I added a line of moving a field in. It doesn't help. what kind of DoEvents I can use?
Mindy |
|
|
|
Apr 10 2012, 07:11 PM
Post
#6
|
|
|
UtterAccess VIP Posts: 1,857 From: BC, Canada |
I thought about the timing too so I added a line of moving a field in. It doesn't help. what kind of DoEvents I can use? Mindy CODE Forms!frmentry.TabCtlEntry.Value = 1 Forms!frmentry.sfmREC.SetFocus DoEvents Forms!frmentry.sfmREC.Form!comReview.SetFocus This would give the application time to finish other things before setting focus to the control. Not sure if it will work, just something to try. I have sometimes found it worked in certain cases. The alternative approach you could try would be a bit more of a change... you could move the code to the subform itself and expose it as a public method. But we'll hold off on it for now until we know if DoEvents did the trick reliably. Mike |
|
|
|
Apr 10 2012, 07:24 PM
Post
#7
|
|
|
UtterAccess Member Posts: 43 |
I tried. DoEvents doesn't help. I am not sure how to do what you suggested -- move code to subform then expose it as public. Could you please explain more???
Thanks. |
|
|
|
Apr 10 2012, 07:39 PM
Post
#8
|
|
|
UtterAccess VIP Posts: 1,857 From: BC, Canada |
I tried. DoEvents doesn't help. I am not sure how to do what you suggested -- move code to subform then expose it as public. Could you please explain more??? Thanks. In the subform itself, you would use code somethig like this: CODE Public Sub FocusOnReview Me.comReview.SetFocus End Sub Then in the main form: CODE Forms!frmentry.TabCtlEntry.Value = 1 Forms!frmentry.sfmREC.SetFocus Forms!frmentry.sfmREC.Form.FocusOnReview It feels like a bit of a hack, I know, but sometimes this kind of thing can work. In fact, if you get comfortable creating methods in subforms it can actually help you remove a lot of headache in complex applications. Rather than have subform-specific code in the parent form, put it into the subform and merely call it from the parent form. Mike |
|
|
|
Apr 10 2012, 07:49 PM
Post
#9
|
|
|
UtterAccess Member Posts: 43 |
I am not sure how this work. Originally I put the SetFocus in the last control of subform. Now, I need to put in Main form. Where is it in main form? how can this code be called?
|
|
|
|
Apr 10 2012, 09:09 PM
Post
#10
|
|
|
UtterAccess Ruler Posts: 2,668 |
What I'd try is in each Form that your Subforms are based on, in their Form_Current events, set the Focus to the appropriate Control for that Form.
BTW, DoEvents is always a good thing to try, when possible timing problems raise their ugly heads! Only takes a few seconds to try, and does now harm, even if it doesn't work! Linq ;0)> |
|
|
|
Apr 10 2012, 10:49 PM
Post
#11
|
|
|
UtterAccess Member Posts: 43 |
I also tried the way you suggested but it didn't work. I really couldn't figure out. It just skipped to next field.
|
|
|
|
Apr 11 2012, 01:21 AM
Post
#12
|
|
|
UtterAccess Ruler Posts: 1,090 |
what control Event you use in switching Tab. If it is in KeyDown or KeyUp you can use KeyCode = 0 inside this procedure.
|
|
|
|
Apr 12 2012, 07:17 PM
Post
#13
|
|
|
UtterAccess Member Posts: 43 |
I use keydown to check if it is tab key or return key. I am not sure what do you mean to use keycode=0. Please explain. thanks.
|
|
|
|
Apr 13 2012, 02:28 AM
Post
#14
|
|
|
UtterAccess Ruler Posts: 1,090 |
when you used the keydown event to inspect the key just pressed, in this case the TAB or RETURN, the TAB/RETURN is still in the KEYBOARD buffer.
You need to clear this buffer first by issuing KeyCode = 0. So on your code, TAB/RETURN is inspected. If found any of these keys it switches Page, but since TAB/RETURN keycode is still in the keyboard buffer, it will TAB/RETURN from the first control. In pseudocode: CODE 'check keyboard buffer 'if TAB or RETURN then 'clear keyboard buffer KeyCode = 0 'switch to page# of tab control 'end if This post has been edited by arnelgp: Apr 13 2012, 02:31 AM |
|
|
|
Apr 14 2012, 07:21 PM
Post
#15
|
|
|
UtterAccess Member Posts: 43 |
Thank you very much. It works. I find a way to go around it. But your way is the best one.
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 25th May 2013 - 01:01 PM |