I want to trap the keystroke for double quotes and prevent the user from entering it in some text boxes. In VBA, the code would be like this:
VB Code:
If KeyCode = 34 Then
DoCmd.CancelEvent
After searching the forum, I came up with this for the vb.net version:
VB Code:
Private Sub txtModName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtModName.KeyDown
If Asc(e.KeyCode) = Keys.OemQuotes Then
e.Handled = False
End If
End Sub
But it doesn't work. When I put a breakpoint in and check the e.keycode, it shows the Shift key used to get the doublequotes; oemquotes is 222. How can I trap this? Thanks.
Last edited by salvelinus; Dec 16th, 2003 at 11:06 AM.
Well, that doesn't work. e.shift = true, but e.keyvalue = 16, which is the "data link escape" character, whatever that means. This is a standard keyboard.
KeyPress doesn't intercept the Shift character like KeyDown does, but it doesn't have the same properties.
There's another weird problem with the textboxes, maybe they're related, though I don't see how. I get the user name via API, it shows fine in a msgbox, but won't show in the textbox, even though setting a breakpoint and checking the value if text1.text shows the value there.
I get an error "Not a valid solution file" when I try to open the uncompressed file. The code .vb file opens ok, but no design .vb
I'm using .net 7.0, if that makes a difference, and keypreview is set to true on the form.
I think what's happening is that the keydown event first catches the shift press, so e.shift is true, but it doesn't catch the e.keyvalue till the next press, where shift is no longer in the keydown event. At this point, e.keyvalue does equal 222. Anyway, I've tried different variations, and the quotes still display.
This is a minor part of the program, could probably skip it, but it bugs me.
Last edited by salvelinus; Dec 16th, 2003 at 10:11 AM.
The attached project is VB.NET 2003 . Basically , you need VB.NET 2003 to run the proj or get it converted with the tool in my signature . Concering the keyvalue of DQoutes , which I got it by different project (look the attachement) , I showed you how to detect while these combination are being pressed , then it's your part to handle them .
I can't guess why it's not showing since I didn't see the code but initially store the retrieved value in a string variable and use the variable into the messagebox .