ACC: How to Determine the View in Which a Form Is DisplayedLast reviewed: June 8, 1997Article ID: Q98229 |
The information in this article applies to:
SUMMARYAdvanced: 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.
MORE INFORMATIONTo 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)If the form is in Form view, the returned value is a nonzero number. If the form is in Datasheet view, the returned value is zero. NOTE: In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic. NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.
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 REFERENCES"Microsoft Windows 3.1 Programmer's Reference," Volume 2 |
Keywords : kbprg PgmApi
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |