UI Automation finds only the Access form, not the WKL control
Environment
WKL Forms Object Library in Access forms (all releases), queried by a UI Automation client such as a
test tool or an accessibility checker: AutomationElement.FromPoint over the control, or a walk of the children of the form's
element. Microsoft 365 Access, 32 bit.
Cause
Access presents a form to UI Automation as its own element and does not list the windows of the
ActiveX controls on it as children of that element. FromPoint over a WklNavBar, WklActionBar or
WklGrid therefore returns the form (or the Access main window), and the raw view of the form shows
no child for the control. The control is not missing: every WKL control that has a window answers UI
Automation from that window itself - the navigation bar as a list named “Navigation” with one item per
entry, the grid as a data grid with rows and cells, the command bar as a tool bar.
A screen reader such as Narrator reaches the controls with the keyboard (Tab into the control): the control then has the focus, and UI Automation reports the focused element of the control's window.
Resolution
Find the control's window by its window handle and ask that window:
- Find the form's window (
OForm; a page in a subform control isOFormSub) below the Access main window of your own Access process (Application.hWndAccessApp). - Enumerate its child windows (
EnumChildWindows) and keep the visible ones whose class name starts withWindowsForms10. A control usually has two windows of the same size, the OLE host and the control's view; take the innermost one. - Call
AutomationElement.FromHandlewith that handle. Pick the control among several by what UI Automation reports, for example the control type List and the name “Navigation”.
Access recreates the window of a control when its width changes or when it is disabled and enabled
again; look the handle up anew before each use. Ask only windows of your own Access process and never
search from AutomationElement.RootElement: such a search also asks every other program on the
machine, including other Access instances.
Related topics
- Copy and paste fail after many Access sessions: why a UI Automation client should ask only its own Access process.