Solved

KeyDown event fires twice with SSTab - Any work-around?

Posted on 1998-09-13
6
381 Views
Last Modified: 2011-10-03
There is a bug with the SSTab which causes the KeyDown event to fire twice.  I'm using VB 4 and the latest version of the SSTab control for VB 4.  This bug is causing havoc with my program!!  I have a form with a SSTab on it and when the user presses F2, I use the KeyDown event to show a modal dialog.  Because of this bug, the dialog is actually shown twice!

How do I get around this problem?  Note that the event only fires twice when the tabs at the top have the focus.  A way around this problem could be to block the second event; but I am worried about future compatibility.  For example, if a new version of the control is realeased which my end users have installed on their machine which doesn't contain the bug, the work-around could break my program.  

Thanks for your help.
0
Comment
Question by:Richard2000
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1434622
Set .KeyPreview of the form to True, and process the form_keydown event
0
 

Author Comment

by:Richard2000
ID: 1434623
MikeP,

Thanks for your answer.  Unfortunately, I *HAD* been using the KeyDown event of the *FORM* which is where the problem occurs.  It seems that whenever a SSTab is on a form, the KeyDown event of the form will fire twice when a tab on a SSTab has the focus.
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1434624
You can use a global variable, set it to True before .Show 1, and to False after it. Before setting it to true, check if it is already true, and exit if it is. I dont see how this can cause compatibility problem
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Richard2000
ID: 1434625
MikeP,

I had some problems getting this technique to work.  I have found a work-around myself - simply enter KeyCode = 0 at the end of the form_keydown event.  This ensures the event will only fire once.  Please lock the question and I will give you the points for making some suggestions :-)
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1434626
Since my suggestions weren't too helpfull, better delete the questions, and get the points back
0
 
LVL 1

Accepted Solution

by:
jonder earned 50 total points
ID: 1434627
You can reject this if you want to but the answer is very simple!
I had the same problem you are having about 9 months ago.
The way I fixed the problem was to make a Global Integer & set it to ZERO, then when your user presses F2

the KeyDown_Event would start off:

GlobalInteger = GlobalInteger + 1
If GlobalInteger > 1 Then
    ...'Your Code
    ...
    GlobalInteger = 0  
End If
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 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

20 Experts available now in Live!

Get 1:1 Help Now