Microsoft KB Archive/98229

= ACC: How to Determine the View in Which a Form Is Displayed =

Article ID: 98229

Article Last Modified on 5/9/2003

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q98229



SUMMARY
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 &quot;Introduction to Programming&quot; manual in Microsoft Access version 1.x, or the &quot;Building Applications&quot; manual in version 2.0.



MORE INFORMATION
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)

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 &quot;User&quot; (ByVal hwnd%,_                      ByVal nIndex%) Declare Function GetWindow% Lib &quot;User&quot; (ByVal hwnd%, ByVal wCmd%) Declare Function IsWindowVisible% Lib &quot;User&quot; (ByVal hwnd%) Declare Function GetClassName% Lib &quot;User&quot; (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     ' &quot;OFormSub&quot;.

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$ = &quot;OFormSub&quot; Then Exit Do        End If

' Get the next sibling window. SiblingHwnd% = GetWindow(SiblingHwnd%, GW_SiblingHwnd%)

Loop Is_FormView = SiblingHwnd%

End Function

