Microsoft KB Archive/95444

= ACC: How to Create Floating Pop-Up Menus (1.x/2.0) =

Article ID: 95444

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 Q95444



SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes how to create &quot;floating&quot; pop-up menus using a combination of Microsoft Windows application programming interface (API) calls and Access Basic code.



MORE INFORMATION
To create a floating pop-up menu, follow these steps:

 Create a new form called Pop-up Menu Form.  Add a list box control called Menu to the form. Make the control large enough to display each of the strings it contains without displaying a scroll bar. Set the control's properties as follows:

     List Box Properties --     ControlName:   Menu RowSourceType: Value List RowSource:    String1;String2;String3;String4 AfterUpdate:  =ItemSelected([Menu]) Left:         0 in      Top:           0 in      FontName:      System FontSize:     8 FontWeight:   Bold

NOTE: Specify the menu strings in the RowSource property. Separate succeeding string values with a semicolon character.   Change the properties of the Pop-up Menu Form as follows:

     Form Properties ScrollBars:     Neither Popup:          Yes RecordSelectors: No     Width:           

Section Properties -     Height:          

 Save the form and close it.  Create a new module and type the following code into the Declarations section for the module.

'NOTE: Some of the following Windows API functions may be 'defined in an existing Microsoft Access library. If so, the new 'declarations would cause a duplication procedure name error. If 'this error occurs, remove the offending declare statement from 'your code or convert the declaration to a comment.

'NOTE: In the following sample code, an underscore (_) is used 'as a line continuation character. Remove the underscore when 're-creating this code in Access Basic.

<pre class="fixed_text">     Option Explicit Type POINTAPI x As Integer y As Integer End Type

Global Const GWL_STYLE = (-16) Global Const WS_DLGFRAME = &H400000

Declare Sub GetCursorPos Lib &quot;User&quot; (lpPoint As POINTAPI) Declare Function GetWindowLong& Lib &quot;User&quot; (ByVal hWnd%, _                         ByVal nIndex%) Declare Function SetWindowLong& Lib &quot;User&quot; (ByVal hWnd%, _                         ByVal nIndex%, ByVal dwNewLong&) </li>  Type the following functions:

<pre class="fixed_text">     Function ShowPopup Dim coord As POINTAPI Dim attr&

GetCursorPos coord DoCmd OpenForm &quot;Pop-up Menu Form&quot;

attr& = GetWindowLong(Forms![Pop-up Menu Form].hWnd, GWL_STYLE) attr& = SetWindowLong(Forms![Pop-up Menu Form].hWnd, GWL_STYLE, _                   attr& And Not WS_DLGFRAME)

DoCmd MoveSize (coord.x * 14), (coord.y * 14),, 1100 End Function

Function ItemSelected (WhichItem As String) DoCmd Close MsgBox &quot;The selected item was &quot; & Trim(WhichItem) End Function </li> Choose the form in which you want the pop-up menu to appear. Open the form in Design view.</li>  Select the event property that you want to use to activate the pop-up menu and specify the following function call:

<pre class="fixed_text">     =ShowPopup

</li></ol>

When you open your form and cause the event assigned in Step 8 above, the pop-up menu appears at the current mouse position. The menu remains on the screen until you select an item from the pop-up menu.

Additional query words: shortcut adt

Keywords: kbhowto kbprogramming KB95444

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.