Solved

Keypreview Events and Combo Box Problem

Posted on 1998-08-06
1
489 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 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