Solved

Keypreview Events and Combo Box Problem

Posted on 1998-08-06
1
495 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
1 Comment
 
LVL 5

Accepted Solution

by:
tuvi earned 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

809 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