Set Focus on tab control

Hargo

Registered User.
Local time
Today, 08:51
Joined
Sep 4, 2014
Messages
19
Hi

On my data entry form I have a tab control with three pages

At the bottom of the first page I have a sub form with 3 fields

Currently, when tabbing, the focus runs through the fields as per the tab order

BUT

Once it gets to the subform (datasheet view) it jumps into the first field of the first record rather than the first 'empty cell' thereby starting a new record in the datasheet.

Once the three fields in the datasheet are completed the focus tabs back to the top of the first page of the form rather than onto the next page of the form

Could someone tell me how to correctly reference controls using VBA so I could SetFocus where I want?

The Main form is called frm_Admissions

It has three pages called Patient, Treatment & Service Providers

Patient has a subform called sub_Cluster (which may or may not hold Cluster Information)

I would like the tab order to jump from the last textbox on the form into the first field of a new record in the datasheet (rather than the first field of any existing records)

Once it has finished in the datasheet I need to tab to the first field/textbox in the Treatment's page of the form rather than back to the first field/textbox in the Patient's page

Any suggestions gratefully received







Any help guys?
 
Last edited:
I suspect my first post was too vague so hopefully this helps....



I have tried using this as a response to the tab key being pressed whilst in the last field on page 1 of my tab control:

Private Sub Combo8_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
Me.[Tabbed Admission Form].Pages.Item("Treatment").[Unit Code].SetFocus
End If
End Sub


I want to go to the first field(Unit_Code) on page 2(Treatment) but I get a '2465' Run-time error:

Microsoft Access can't find the field '|1' referred to in your expression


Any idea what's wrong?


Thanks
 
Tab order affects the controls in the form itself. A subform control houses a form and it also has it's own tab order, so we can't expect it to jump out of the subform control and move on to the next item in the parent control.
Once it gets to the subform (datasheet view) it jumps into the first field of the first record rather than the first 'empty cell' thereby starting a new record in the datasheet.
By trapping the Tab key (as you're already doing), you only need to:
1. set focus to the page
2. set focus to the form within the subform control using the syntax spikepl referenced
3. use DoCmd.GoToRecord (or the form's recordset) to move to a new record

Once the three fields in the datasheet are completed the focus tabs back to the top of the first page of the form rather than onto the next page of the form
Similar process as described above with.
 

Users who are viewing this thread

Back
Top Bottom