Solved

opening a combobox without the mouse

Posted on 1998-06-12
3
144 Views
Last Modified: 2010-05-03
i have a combobox that i want the user will be able to display the combo list without clicking the mouse, but by pressing a combinations of keybords keys, for example shift + a. how do i do this?
any help will be much appriciated!
yny
0
Comment
Question by:yny
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
peterwest earned 200 total points
ID: 1463189
Hi there,

First of all put the following in a module:

Public Const CB_SHOWDROPDOWN = &H14F

Public Declare Function SendMessageByNum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)


Now set the keypreview property for the form you are working on to true and put this code in the KeyDown event of the form:

    'Declare local variables
    Dim lRetVal As Long

    'If alt was held down then...
    If Shift = 4 Then
       
        'Look at the key that was pressed with ALT
        Select Case KeyCode
        Case 64 'A pressed with ALT
             lRetVal= SendMessageByNum(Combo1.hWnd,CB_SHOWDROPDOWN,0,0)

        End Select

     End If


You should now find that if the user pressed ALT+A when any control on the form has focus then the Combo1 combobox will drop down.

Hope this is what you're after.

Pete

0
 

Author Comment

by:yny
ID: 1463190
that was exactly what i was looking for.
just a small remark: in order to show the dropdown list, the third parameter of the function must be 1 (nonzero).
thanks very much
yny
0
 
LVL 2

Expert Comment

by:peterwest
ID: 1463191
Cheers,

Sorry about that last param - I was in a bit of a rush to get the answer sorted out and didn't read the API manual properly.

Pete

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now