ACC: How to Determine the View in Which a Form Is DisplayedID: Q98229
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
Microsoft Access has no built-in functions or properties to determine if a
form is displayed in Form view or Datasheet view. To determine this, you
must call a series of Windows application programming interface (API)
functions.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information on Access Basic, please refer
to the "Introduction to Programming" manual in Microsoft Access version
1.x, or the "Building Applications" manual in version 2.0.
To determine the current view of a form, call the function listed
below and pass the form as an argument to the function, for example:
X% = Is_FormView (Forms!Form)
Option Explicit
Declare Function GetWindowWord% Lib "User" (ByVal hwnd%,_
ByVal nIndex%)
Declare Function GetWindow% Lib "User" (ByVal hwnd%, ByVal wCmd%)
Declare Function IsWindowVisible% Lib "User" (ByVal hwnd%)
Declare Function GetClassName% Lib "User" (ByVal hwnd%,_
ByVal lpClassname$, ByVal nMaxCount%)
Const GW_SiblingHwnd% = 2
Const GW_CHILD = 5
Function Is_FormView (F As Form)
Dim SiblingHwnd%, CName$, CNameLen%
' Get the first child window of the specied form.
SiblingHwnd% = GetWindow(F.hwnd, GW_CHILD)
' Enumerate through the forms child windows until exhausted
' or you find a visible sub-window with the classname of
' "OFormSub".
Do While SiblingHwnd%
'allocate temporary space.
CName$ = Space$(128)
' Get the class name of the specified window.
CNameLen% = GetClassName(SiblingHwnd%, CName$, Len(CName$))
' Peel off the extra characters in the padded string.
CName$ = Mid$(CName$, 1, CNameLen%)
' If the window is visible, and the classname is OFormSub,
' then the form is either in Design view, or Form view and
' not in Datasheet view.
If IsWindowVisible(SiblingHwnd%) And CName$ = "OFormSub" Then
Exit Do
End If
' Get the next sibling window.
SiblingHwnd% = GetWindow(SiblingHwnd%, GW_SiblingHwnd%)
Loop
Is_FormView = SiblingHwnd%
End Function
"Microsoft Windows 3.1 Programmer's Reference," Volume 2
Keywords : kbprg
Version : 1.0 1.1 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: March 22, 1999