Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


vaSpread and Tab

Posted on 1999-06-29
Medium Priority
Last Modified: 2010-05-18
I am using the Farpoint vaSpread 2.5.55 and VB 5.0.  I have a spread with 9 columns.  Whenever the user keys a value and hits "Enter", the spdDetail_LeaveCell event is fired.  This is where I do my validation.  Depending on the column, I do the appropriate validation.  

My problem is that whenever you hit the "Tab" key, it bypasses the spdDetail_LeaveCell event, and no validation occurs.  I have the "Process Tab Key" property set to true, so the focus is moved to the next cell in the spread.  This still results in no spdDetail_LeaveCell event being fired.

I have tried using the spdDetail_KeyDown event, but with funky results.  Any suggestions?  I know, don't use Farpoints Spread!!!

Thanks in advance,
Question by:Preece
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

jaywalk earned 200 total points
ID: 1520772
Ok. The tab key is processed by VB _BEFORE_ any messages are sent to your controls. So you can't ever process it. You can achieve the same result, however, by using the following:

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Const VK_TAB = 9&

Private Sub spdDetail_LostFocus()
    If GetKeyState(VK_TAB) And 128 Then
        Debug.Print "Tab was pressed"
    End If
End Sub

The actual specification says "If the most significant bit is set, the key is down".

Of course, if spdDetail doesn't have a LostFocus event, then this isn't going to work. ;p


LVL 12

Author Comment

ID: 1520773
I tried your code. spdDetail does have a lostfocus event.  But I am confused as to what the

if GetKeyState(VK_TAB) And 128 then

is supposed to return.  What does 128 represent?  The GetKeyState returned 1 in one test and 0 in another.

LVL 12

Author Comment

ID: 1520774
This solution works quite well.  Sorry for the delay!  Thanks for your help.


Expert Comment

ID: 1520775
128 represents 10000000 in binary
-127 comes out as 10000001.

The return values for GetKey(9&) when tab is pressed are one of those two (or should be). The actual documentation says "When the high order bit is set, the key is down".

So if you do a binary 'and' with the result and 128, you get either zero or not zero. True or false. =)


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 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