Solved

Keypreview Events and Combo Box Problem

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

929 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

12 Experts available now in Live!

Get 1:1 Help Now