Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Keypreview Events and Combo Box Problem

Posted on 1998-08-06
1
Medium Priority
?
510 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 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

772 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