Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Keypreview Events and Combo Box Problem

Posted on 1998-08-06
1
Medium Priority
?
504 Views
Last Modified: 2012-08-13
Hi,
I use the Keypreview = Yes and the KeyDown Event to simulate a datasheet view on a form view.  ie if you press the down key, the focus moves to the next record, as opposed to the next control.

This works fine, but when you are on a combo box, and you use the "Alt + Down Arrow" key combination to view your options in the combo box (just the same as pressing F4), the Keycode event kicks in and moves to the next record, as opposed to displaying the combo box.

Now I've got around the problem a little bit by rejecting the keystroke if the Alt key is being held down, but the problem of moving around in the combo box while it is dropped down remains.

ie, you can drop the combo box down by pressing Alt + Down Arrow, but then when you use the down arrow key to move within the combo box, it moves to the next record.

So, I guess my question comes down to : How can you tell if a given combo box is "Dropped Down" or not.

Thanks in advance

Malcolm Trevena
0
Comment
Question by:trevena
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
tuvi earned 800 total points
ID: 1958351
You cannot tell whether the combo box is dropdown or not, at least not in Access. But there is a way to get around this problem. In your form's KeyDown procedure, if there is a downkey pressed, then test if the active control is a combo box, don't do anything; let the combo box handle it but put a tag in it. Now, on the exit event of the combo box, if the tag is set, then it means it is not in a dropdown state, hence go to a new record; otherwise reset the tag. Here is my sample code:

Private Function IsAlternate(KeyCode As Integer, Shift As Integer) As Boolean
If (Shift And acAltMask) <= 0 Then
  IsAlternate = False
Else
  If ((Shift And acCtrlMask) > 0) Or ((Shift And acShiftMask) > 0) Then
    IsAlternate = False
  Else
    IsAlternate = True
  End If
End If
End Function

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
PartID.Tag = ""
If KeyCode = vbKeyDown Then
  If ActiveControl.Name = PartID.Name Then
    If Not IsAlternate(KeyCode, Shift) Then
      PartID.Tag = "down"
    End If
  Else
    KeyCode = 0
    DoCmd.GoToRecord , , acNewRec
  End If
End If
End Sub

Private Sub PartID_Exit(Cancel As Integer)
If PartID.Tag = "down" Then
  PartID.Tag = ""
  Cancel = True
  DoCmd.GoToRecord , , acNewRec
End If
End Sub

PartID is the name of my combo box. Remember in design mode, set PartID's tag to blank string "".

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

721 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