Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2003, 09:10 PM
Authorized User
 
Join Date: Jun 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ked Code problem

The code below prevents the entry of non-numeric values in a text box. In addition it accepts tha Tab and Backspace key. All other key entries are not allowed. I would like the user to paste values in the textbox using Ctl+V keys together.

How can I write a code to accept the Ctl and the V keys together.

Private Sub MedRecNo_KeyDown(KeyCode As Integer, Shift As Integer)

   Select Case KeyCode
        Case 8, 9, 13, 17, 27, 32, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57
           ' do nothing
        Case Else
            msg = MsgBox("Only numeric values are allowed for Medical Record Number", , "Numeric Values Only Allowed")
            KeyCode = 0
    End Select



End Sub
 
Old June 13th, 2003, 08:04 AM
Registered User
 
Join Date: Jun 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Diahann Send a message via Yahoo to Diahann
Default

I've tried this on a form to recognize key combinations, maybe you can manipulate the code for your text box.

Like......
Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
 If KeyCode = Asc("V") And Shift = 2 Then
     MsgBox "Control V"
  End If
End Sub

Don't know if this helps.
D...
 
Old June 13th, 2003, 08:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

You might be better off doing such editing in the KeyPress event. Test to see if the value is a legal one, and set the KeyAscii value to 0 if it is not, thus simply throwing away the bad input rather than displaying a message box. This has the behavior that when the user tries to type '123x', the 'x' simply doesn't display - only numerics (or whatever your legal values are) appear. E.g.
Code:
If Not(KeyAscii > 47 And KeyAscii < 58) Then KeyAscii=0
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with example code? j_nord BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 February 28th, 2007 04:03 PM
Code behind problem.. shabirmaher General .NET 1 August 12th, 2005 03:09 AM
problem in code HumaMunir BOOK: Beginning Java 2 3 May 16th, 2005 09:19 AM
problem on example code zerocold C# 0 July 15th, 2004 04:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.