vbams-accessms-access-2016setfocussplitform

Access splitform how to move the caret (or set the focus) from the sheet section to the form section and viceversa


Situation:

Hi, in Access 2016 I have a db I created with a form set as splitform mode: the sections position are as follows:

  1. upper portion: shows the datasheet portion of the splitform with a bunch of columns (=fields) and more or less 1500 rows (=records) of various commercial products;
  2. lower portion: shows the form portion of the splitform

Now, the lower portion that shows the form portion of the splitform, is showing its form header and of course the form body (details).

  1. a date control
  2. a combo-box (that is the control used to filter the datasheet part of the splitform)
  3. a button (that is used to empty the 2nd control and to remove the filters applied by the 2nd control to the datasheet section)

The 1st and the 2nd of the previous controls are not "connected" to any table: in other words their relative Control Origin Property is blank.

Here is a screenshot: Here is a screenshot

The problem

The problem basically is: how can I move by using VBA the caret position from one section to the other of the split form? I mean, usually you can do:

control.SetFocus

or even

DoCmd.GoToControl MyControlName

to move the caret to the control where you need it. But if I am into the sheet section of the splitform I can't do this:

Private Sub Form_Current()
   MySubForm.SetFocus
'Or alternatively:
   DoCmd.GoToControl "MySubFormName"
End Sub

because it seems that Access from the sheet section "doesn't see" the sub form that is into the body (details) of the form section of the splitform.

Of course I know I can use the mouse or the keystroke F6 or Shift+F6 to move around do that, but since the data insertion work flow is always the same I wish to write some VBA that does it for me.

I wish to go from the data-sheet-view section of the main form (the splitform) to the subform that is of course into the body of the form section of the splitform

What I have also tested

I have also tested sendkeys "{F6}"to exit from sheet section and go to the form section than SubFormName.SetFocus to move the focus focus to the subform

Viceversa, when I write a filter into the combobox I want to go to the sheet section: so I tried: sendkeys "+{F6}"

Sendkeys unfortunately does not work every time: well actually a lot of times the focus ends up to the Access Ribbon or somewhere else where I don't need.

So my question is:

Is there a better or even an optimal solution to this inconvenient so I don't have to use sendkeys that fails most of the time?

So basically I would like to use something like the following Pseudo-code:

SplitForm.DataSheetSection.setfocus and of course to go back to the form section: SplitForm.FormSection.setfocus from here I can easly do: mySubForm.setfocus to go to the sub form, or similar code to go to the Filter control combo-box, depending on the triggered event.

IMHO it seems a very simple behavior for VBA, in theory, but in practice I have searched online for more than a week now and I am loosing hope. So, if it is possible, I don't want to be forced to go back to a pre-SplitForms age and use another subform set as datasheetview and synchronize them all by VBA, if exists a clean solution to implement it with a splitform.

Is it possibile? If yes, how can I implement it?

If more infos are needed please ask in comments: I will add to this asaic.

Thank you all in advance.

Edit 2025.05.12

As already said Access allows to change section in a split form by pressing on the computer keyboard:

What is the equivalent DoCmd.RunCommand acCmdCommandName that is executed when such keystrokes are pressed?

Or is there a docmd.runcommand equivalent in vba?

Edit 2025.05.13

I also have checked the form with a Window Info tool that returns these results about the data grid part of the split form:

>>>> Control <<<<
Class:  OGrid
Instance:   2
ClassnameNN:    OGrid2
Name:   
Advanced (Class):   [CLASS:OGrid; INSTANCE:2]
ID: 
Text:   
Position:   2, 160
Size:   1900, 440
ControlClick Coords:    727, 172
Style:  0x52000000
ExStyle:    0x00000000
Handle: 0x001804E2

Is there a way to get a handle of the datagrid section and programmatically move the caret there? Unfortunately there are some absent properties of that control: the Name and the ID for example. I share it here with the hope can be useful in some way to face and solve such a little problem.


Solution

  • As you may be aware by looking at it in design view, a split form is in fact a modified single form.

    For that reason, I don't believe it is possible to achieve what you want using VBA. There are many limitations in what you can do due to the way that built-in split forms are designed. These include several different display issues, runtime issues and code issues. See Split Form Issues for details

    I would recommend you replace it with your own form that has similar functionality but allows you more control over the layout. The above article also includes links to several alternatives.