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

Event on Tab - move to next control on subform

Status
Not open for further replies.

wz

Programmer
Feb 16, 2001
88
US
I want the end user to use tab key to go to another control. The end user is entering data into a list (using enter between fields) and when they are completed (never the same amount of records) I want the cursor to move to next field in next subform.

I have used the following code to change focus (it works) on a differnet project when the end user moves to different subform.

Forms![formname]![subformname].SetFocus
Forms![formname]![subformname]![controlname].SetFocus

Any help in using the tab? or a different key?
 
How are ya wz . . .

Capture the tab key in the forms [blue]On Key Down[/blue] event and do what you want with it!

I use a common function so you don't have to write the code more than once. Therefore ... in a module in the modules window, copy/paste the following function:
Code:
[blue]Public Function TabHandler(subFormName As String, KeyCode As Integer, Shift As Integer) As Boolean
      
   If (Shift = 0) And (KeyCode = vbKeyTab) Then
      If subFormName = "[purple][B][I]FormName1[/I][/B][/purple]" Then
         [green]'set focus to next subform/textbox[/green]
         TabHandler = True
      ElseIf subFormName = "[purple][B][I]FormName2[/I][/B][/purple]" Then
         [green]'set focus to next subform/textbox[/green]
         TabHandler = True
      End If
   End If

End Function[/blue]
In the [blue]On Key Down[/blue] event of each subForm of interest, copy/paste the following:
Code:
[blue]Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   
   [green]'Do not pass Tab to system if used by code![/green]
   If TabHandler(Me.Name, KeyCode, Shift) Then KeyCode = 0

End Sub[/blue]
Perform your testing! ...

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Wz . . .

Almost forgot ... be sure the subforms [blue]Key Preview[/blue] event is set to [blue]Yes![/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks for your help.

It works - in part. I am able to move to the next subform. However, I cannot use the mouse to move the cursor back to previous subform if a correction is needed. I reversed what I did and it seems that this problem existed before this code. Any ideas as to why I cannot go back to the subform to edit if nessessary (by using my mouse)? If I advance to next record & return I can edit all again. (I have a 3 page form with 2 subforms on this page) Do I need to do a refresh?

wz
 
wz . . .

Do you get an error message?

What version Access?

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
nope, no error message...version 2007
wz
 
wz . . .

2007 raises a red flg for me. Already has too many problems! [surprise]

Any chance you can upload a scaled down model of the db thru 4Shared.com and post the link here? ... (Its free!). Before you upload, it would help if you could save to an earlier version 1st ... specifically 2000.

BTW: In June 2008 I sent a letter to all my clients, [red]forbidding them to move to 2007![/red] ... least my services extinguish! ...

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
dear me, just my luck.

I'll try my best to refresh or whatever to clear up.

I'm not going to post - at this point. It's huge...I have at least 40 tables linked, etc. Thanks for your help though, wz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top