By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Combination of "Key Down" & "Not in List" events produce error 7777

doma23
100+
P: 107
I have two comboboxes, cmbClient and cmbCountry.
Both combos have On Key Down events set, so the user can easily go trough the combo values.

Combo Client has "After Update" and "On Key Down" event set, and it works fine.
I used After Update event to take care manually (via code) the items that are not in the list.

On combo Country, however, there was no need for that and I've used "On Not in List" event instead. And that was working fine until I've added the "On Key Down" event.
Now as soon as I press the down cursor, it activates "Not on List" event and it gives me the message that the item is not on the list, although it obviously is.
After I press OK button, I get additional error "Run-time error 7777: You've used the Listindex property incorrectly."
When I go to debug, the next line is higlihted:
"Me.cmbCountry.ListIndex = Me.cmbCountry.ListIndex + 1"

Here is the full code of the KeyDown event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbCountry_KeyDown(KeyCode As Integer, Shift As Integer)
  2.  
  3.     Select Case KeyCode
  4.         Case vbKeyDown
  5.             KeyCode = 0
  6.             If Me.cmbCountry.ListIndex <> Me.cmbCountry.ListCount - 1 Then
  7.                 Me.cmbCountry.ListIndex = Me.cmbCountry.ListIndex + 1
  8.             End If
  9.         Case vbKeyUp
  10.             KeyCode = 0
  11.             If Me.cmbCountry.ListIndex > 0 Then
  12.                 Me.cmbCountry.ListIndex = Me.cmbCountry.ListIndex - 1
  13.             Else
  14.                 Me.cmbCountry.ListIndex = 0
  15.             End If
  16.     End Select
  17.  
  18. End Sub
  19.  
Nov 29 '11 #1

✓ answered by doma23

I have comboboxes on the form and I want to give the users of my tool the possiblity to scroll down and up through the values of the comboxes only with the cursor keys, without the use of mouse.
The feature is very useful.

Anyway, I've solved the problem, by adjusting the code:
Expand|Select|Wrap|Line Numbers
  1.     Select Case KeyCode
  2.         Case vbKeyDown
  3.             KeyCode = 0
  4.             If Me.cmbCategory.ListIndex <> Me.cmbCategory.ListCount - 1 Then
  5.                 Me.cmbCategory.Value = Me.cmbCategory.ItemData(Me.cmbCategory.ListIndex + 1)
  6.             End If
  7.         Case vbKeyUp
  8.             KeyCode = 0
  9.             If Me.cmbCategory.ListIndex > 0 Then
  10.                 Me.cmbCategory.Value = Me.cmbCategory.ItemData(Me.cmbCategory.ListIndex - 1)
  11.             Else
  12.                 Me.cmbCategory.Value = Me.cmbCategory.ItemData(Me.cmbCategory.ListIndex)
  13.             End If
  14.         Case vbKeyBack  'backspace puts the value to null, otherwise the previous value would remain
  15.             KeyCode = 0
  16.             Me.cmbCategory = Null
  17.     End Select
  18.  

Share this Question
Share on Google+
4 Replies


TheSmileyCoder
Expert Mod 100+
P: 2,321
I dont get what exactly it is you are trying to do with the keyDown event? Why do you use that, is the normal access filtering/selecting not working good enough for you?
Nov 29 '11 #2

doma23
100+
P: 107
I have comboboxes on the form and I want to give the users of my tool the possiblity to scroll down and up through the values of the comboxes only with the cursor keys, without the use of mouse.
The feature is very useful.

Anyway, I've solved the problem, by adjusting the code:
Expand|Select|Wrap|Line Numbers
  1.     Select Case KeyCode
  2.         Case vbKeyDown
  3.             KeyCode = 0
  4.             If Me.cmbCategory.ListIndex <> Me.cmbCategory.ListCount - 1 Then
  5.                 Me.cmbCategory.Value = Me.cmbCategory.ItemData(Me.cmbCategory.ListIndex + 1)
  6.             End If
  7.         Case vbKeyUp
  8.             KeyCode = 0
  9.             If Me.cmbCategory.ListIndex > 0 Then
  10.                 Me.cmbCategory.Value = Me.cmbCategory.ItemData(Me.cmbCategory.ListIndex - 1)
  11.             Else
  12.                 Me.cmbCategory.Value = Me.cmbCategory.ItemData(Me.cmbCategory.ListIndex)
  13.             End If
  14.         Case vbKeyBack  'backspace puts the value to null, otherwise the previous value would remain
  15.             KeyCode = 0
  16.             Me.cmbCategory = Null
  17.     End Select
  18.  
Nov 29 '11 #3

TheSmileyCoder
Expert Mod 100+
P: 2,321
I still dont see why you need custom code for that. Isn't that standard built-in access behavior? Maybe I am just tired and missing something.
Nov 29 '11 #4

doma23
100+
P: 107
Not in Access 2002 is not. ;)
Nov 29 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.