473,402 Members | 2,061 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,402 software developers and data experts.

vbkeySeparator not working in Access 2003

SOLUTION NEEDED FOR ACCESS 2003 / VBA, NOT FOR ANY VERSION OF VB.

I need to differentiate between the Enter key on the main keyboard and
the numeric keypad and obviously tried using vbkeySeparator in the
form’s Keypress event. However, both Enter keys return KeyCode 13.

MS Q188550 (below) offers a workaround for VB only – it does not claim
to fix VBA. On this basis you might expect that the bug is fixed in
Access/VBA but it isn’t. I have tried the fix in VB and it works fine,
but including the code in an Access 2003 form doesn’t work – the call
to PeekMessage always returns zero. I’ve also tried various different
values for the filter to no good effect.

Many thanks for you help
Dave
- this is the VB fix cribbed straight from the Microsoft knowledge
base...
Private Declare Function PeekMessage Lib "user32" Alias _
"PeekMessageA" (lpMsg As MSG, ByVal hwnd As Long, _
ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, _
ByVal wRemoveMsg As Long) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

Private Type MSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type

Const PM_NOREMOVE = &H0
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const VK_RETURN = &HD

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim MyMsg As MSG, RetVal As Long
' pass:
' MSG structure to receive message information
' my window handle
' low and high filter of 0, 0 to trap all messages
' PM_NOREMOVE to leave the keystroke in the message queue
' use PM_REMOVE (1) to remove it

RetVal = PeekMessage(MyMsg, Me.hwnd, 0, 0, PM_NOREMOVE)

' now, per Q77550, you should look for a MSG.wParam of VK_RETURN
' if this was the keystroke, then test bit 24 of the lparam - if
ON,
' then keypad was used, otherwise, keyboard was used

If RetVal <0 Then
If MyMsg.wParam = VK_RETURN Then
If MyMsg.lParam And &H1000000 Then
MsgBox "Enter from Keypad pressed"
Else
MsgBox "Enter from Keyboard pressed"
End If
End If
Else
MsgBox "No message waiting, or possible problems calling
PeekMessage"
End If
End Sub
Oct 23 '08 #1
4 2642
daved <da*******@googlemail.comwrote:
>I need to differentiate between the Enter key on the main keyboard and
the numeric keypad and obviously tried using vbkeySeparator in the
form’s Keypress event.
Just curious. Why.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Oct 23 '08 #2
On Oct 23, 10:21*pm, "Tony Toews [MVP]" <tto...@telusplanet.net>
wrote:
daved <daved1...@googlemail.comwrote:
I need to differentiate between the Enter key on the main keyboard and
the numeric keypad and obviously tried using vbkeySeparator in the
form’s Keypress event.

Just curious. *Why.

Tony
--
Tony Toews, Microsoft Access MVP
* *Please respond only in the newsgroups so that others can
read the entire thread of messages.
* *Microsoft Access Links, Hints, Tips & Accounting Systems athttp://www.granite.ab.ca/accsmstr.htm
* *Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/
Because I'm writing an EPOS system which needs to use the numeric
keypad Enter as the totalize key, whereas the main keyboard Enter key
is used in its traditional role everywhere else. Visualize the number
pad as the data-entry keys on a cash register if it helps. The number
pad number keys send their characters to specific fields whereas the
main keyboard number (and all other) keys act in the usual way in
whatever field the user happens to be in.

Dave

Oct 23 '08 #3
Update on progress - an imperfect but tolerable solution.

I spent the last couple of days trying some keyboard hooks, They all
seems to work OK in VB but as soon as I port them to Access I run into
problems. I always thought that VB and VBA were essentially the same
but there must be some fundamental difference somewhere. The end
result is that hooks are just not reliable enough: Access would ignore
the call at best and crash at worst.

However, I have discovered one thing. In Access the message queue is
cleared by the time it gets to the form's KeyDown event whereas in VB
it isn't and this led me to consider puting the PeekMessage call in a
loop. After several attempts I've reached the following stage which
works well and reliably but with the quirk that I can't get it to
detect a keydown event, only keyup, unless the key is held down until
the repeat comes into play which is somewhat unnatural for an Enter
key.

The snippets below allow any form to call KbdFix but the code also
works perfectly well if it is all in a single form's KeyDown handler,
with the declarations (see above) private to the form.

' form code
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
KeyCode = KbdFix(KeyCode, Me.hwnd)
...
usual key trapping code goes here
you can now use vbKeySeparator properly
...
End Sub

' common module code, together with declarations (note the new
constant VK_SEPARATOR, or just use &h6C)
Public Function KbdFix(KeyCode As Integer, Hndl As Long) As Integer
Dim MyMsg As MSG, RetVal As Long
Dim keys(0 To 255) As Byte
If KeyCode = vbKeyReturn Then
Do
RetVal = PeekMessage(MyMsg, Hndl, WM_KEYDOWN, WM_KEYUP,
PM_REMOVE)
If MyMsg.wParam = VK_RETURN Then
If MyMsg.lParam And &H1000000 Then
KbdFix = VK_SEPARATOR
Else
KbdFix = VK_RETURN
End If
End If
Loop Until RetVal
Else
KbdFix = KeyCode
End If
End Function
Dave

Oct 25 '08 #4
On Oct 23, 10:41*pm, daved <daved1...@googlemail.comwrote:
On Oct 23, 10:21*pm, "Tony Toews [MVP]" <tto...@telusplanet.net>
wrote:
daved <daved1...@googlemail.comwrote:
>I need to differentiate between the Enter key on the main keyboard and
>the numeric keypad and obviously tried using vbkeySeparator in the
>form’s Keypress event.
Just curious. *Why.
Tony
--
Tony Toews, Microsoft Access MVP
* *Please respond only in the newsgroups so that others can
read the entire thread of messages.
* *Microsoft Access Links, Hints, Tips & Accounting Systems athttp://www.granite.ab.ca/accsmstr.htm
* *Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/

Because I'm writing an EPOS system which needs to use the numeric
keypad Enter as the totalize key, whereas the main keyboard Enter key
is used in its traditional role everywhere else. Visualize the number
pad as the data-entry keys on a cash register if it helps. The number
pad number keys send their characters to specific fields whereas the
main keyboard number (and all other) keys act in the usual way in
whatever field the user happens to be in.

Dave
Update on progress - an imperfect but tolerable solution.

I spent the last couple of days trying some keyboard hooks, They all
seems to work OK in VB but as soon as I port them to Access I run into
problems. I always thought that VB and VBA were essentially the same
but there must be some fundamental difference somewhere. The end
result is that hooks are just not reliable enough: Access would ignore
the call at best and crash at worst.

However, I have discovered one thing. In Access the message queue is
cleared by the time it gets to the form's KeyDown event whereas in VB
it isn't and this led me to consider puting the PeekMessage call in a
loop. After several attempts I've reached the following stage which
works well and reliably but with the quirk that I can't get it to
detect a keydown event, only keyup, unless the key is held down until
the repeat comes into play which is somewhat unnatural for an Enter
key.

The snippets below allow any form to call KbdFix but the code also
works perfectly well if it is all in a single form's KeyDown handler,
with the declarations (see above) private to the form.

' form code
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
KeyCode = KbdFix(KeyCode, Me.hwnd)
...
usual key trapping code goes here
you can now use vbKeySeparator properly
...
End Sub

' common module code, together with declarations (note the new
constant VK_SEPARATOR, or just use &h6C)
Public Function KbdFix(KeyCode As Integer, Hndl As Long) As Integer
Dim MyMsg As MSG, RetVal As Long
Dim keys(0 To 255) As Byte
If KeyCode = vbKeyReturn Then
Do
RetVal = PeekMessage(MyMsg, Hndl, WM_KEYDOWN, WM_KEYUP,
PM_REMOVE)
If MyMsg.wParam = VK_RETURN Then
If MyMsg.lParam And &H1000000 Then
KbdFix = VK_SEPARATOR
Else
KbdFix = VK_RETURN
End If
End If
Loop Until RetVal
Else
KbdFix = KeyCode
End If
End Function
Oct 25 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Arrenbrecht | last post by:
Hi all From one day to another, Access 2003 has stopped working on my XP Prof SP2. Repair, reinstall, reboot, nothing helps. When started from the Start menu, it loads OK, displays the main...
3
by: Max Riedel | last post by:
Hi! In the company where I'm working there are 5 machines setup with Access 2003 and some with 2002. On all but one access isn't functioning properly.Everytime someone tries to query or create a...
2
by: Christine.Misseri | last post by:
Hi all, I'm sure someone knows about this problem. I have an Access database designed in Access 2000, connected to an ORACLE 8i back end. On the ORACLE side I have stored procedures, triggers...
0
by: bmoos1 | last post by:
I've use this lots of times with the same database, but now I'm working on someone elses computer who is using Access 2003 and Word 2003. I can browse for the Query I want to use in my document, ...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
2
by: stuart.medlin | last post by:
I have recently converted an Access 97 database to Access 2003. However, I am running into a problem with using Application.Filesearch to locate a file in my directory. The code follows: ...
10
by: Lindsay Browning | last post by:
Hello, I found a previous posting by someone on the 10th Sept (http://www.thescripts.com/forum/thread705528.html) who seemed to have the same problem as me, but it was never resolved. I have...
1
by: hvtarn | last post by:
Hi all, I am testing the reports on the new server with access 2003 installed. strFileName = "C:\FILES\pricingtool\ReportsOut\test.rtf" strDynRptName = "rpt_WebStdQuoteSum" DoCmd.OutputTo...
5
by: Lysander | last post by:
My collegue had to buy a new laptop that came with Office 2007 already installed. She had Access 2003 installed on top, in a different directory. None of our 2003 databases will run on her...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.