473,625 Members | 3,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 _
"PeekMessag eA" (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(Ke yCode 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(MyM sg, 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 2656
daved <da*******@goog lemail.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...@teluspl anet.net>
wrote:
daved <daved1...@goog lemail.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(Ke yCode 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(MyM sg, 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...@goog lemail.comwrote :
On Oct 23, 10:21*pm, "Tony Toews [MVP]" <tto...@teluspl anet.net>
wrote:
daved <daved1...@goog lemail.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(Ke yCode 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(MyM sg, 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
8937
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 window and the workspace window, but then repeatedly shows the following error: <cite> A problem occurred while Microsoft Office Access was communicating with the OLE server or ActiveX Control.
3
2278
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 report using ANY table, access claims that there were no fields in the table, but that's not true. Also it seems as if we are having some kind of language versions conflict. They only have and ever had German versions installed, but
2
2431
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 and views that kick off at different times. My Access 2000 database works well. Problem: I converted the database to Access 2003 am using ORACLE again as my back end (they have updated the drivers in Oracle to 9i). I an trying
0
1173
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, and when I go to enter the fields into my document, all of thefields are there, but when I do the merge, it doesn't find any records. I've run a repair to Word and one to Access but still the problem exists. What could be wrong?
8
8480
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 perfectly. However, I have code that runs under the ON CLICK event. The code changes the focus to other controls, which means the conditional formatting is no longer displayed. This part makes sense to me. Here's what doesn't make sense. The last...
2
7321
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: ------------------------------- Dim dbDir As String 'Directory where database stored Dim dbPath As String 'Directory + Name of database Dim dbFileName As String 'Name of the database Dim Card1File As String ...
10
11461
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 created a database with many navigation pages which lead to other forms using buttons. Also some forms are populated by combo boxes where you can select the record from a drop down box and it fills that record's details on the form. This all works...
1
1263
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 acOutputReport, strDynRptName, acFormatRTF, strFileName, False The problem is the test.rfs is not created at the strFileName location. I am not sure what are missing with the new access 2003. The reports are working fine in the old server with MS...
5
10528
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 laptop, all giving the error "Form Open- Event, property does not exist" or something like that. This happens with every form. We can access the database, but not open any form. Going into a module of code, we can compile ok, no errors. Checking...
0
8256
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6118
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1500
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.