473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

doma23
107 100+
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.  

4 1845
TheSmileyCoder
2,322 Expert Mod 2GB
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
107 100+
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
2,322 Expert Mod 2GB
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
107 100+
Not in Access 2002 is not. ;)
Nov 29 '11 #5

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

Similar topics

134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
4
by: JvdWal | last post by:
Hi, I've been trying the PDF & Mail Class Library from ACG Soft in combination with Northwind-2k3 style of db. Can someone help me with the error which is popping up: (which I cant get solved..)...
2
by: Kyle Blaney | last post by:
I am using a Listbox and can not get the "drop down" effect. My listbox is populated with 20 items and a vertical scrollbar is automatically added. One item is visible. When I click on the...
4
by: lwickland | last post by:
Non-visual C# objects on a webpage are not marked as "safe for scripting" I'm developing .NET components in C# which are used as ActiveX-style controls on web pages that are displayed inside a...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
9
by: John Salerno | last post by:
There is an article on oreilly.net's OnLamp site called "The World's Most Maintainable Programming Language" (http://www.oreillynet.com/onlamp/blog/2006/03/the_worlds_most_maintainable_p.html). ...
9
by: axs221 | last post by:
I am trying to move some of our large VBA Access front-end file into ActiveX DLL files. I created two DLL files so far, one was a module that contains code to integrate into the QuickBooks...
18
by: njgreen2001 | last post by:
I thought the length of this might give me problems. Any suggestions on how to shorten it? Expression: =IIf(="A Pos" And ="A Pos",(DLookUp("","")), IIf(="A Pos" And ="A...
4
by: jorgejch | last post by:
Hello, I've started with python (3) recently. Initialy only for scripting. Now I'm trying the object oriented bit. I'm getting the following error message <Atom.Atom object at 0x7f0b09597fd0>...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.