Solved

opening a combobox without the mouse

Posted on 1998-06-12
3
153 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replace Formatted Numbers with text 9 61
Visual Basic Excel Formatting error 4 85
Problem to With line 4 43
Set email body to html using vbscript 6 28
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 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

18 Experts available now in Live!

Get 1:1 Help Now