Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 December 13th, 2006, 10:28 PM
Authorized User
 
Join Date: Sep 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unwanted Char - OnKeypress event

Hello all,

to increase datainput speed i have added code to a text box so if the letter "t" is pressed, todays date is entered. The date does appear but the letter "t" is inserted too, any way of stopping this other than check the whole string for a "t" and then remove it?

this is my OnKeypress code:

Private Sub Call_Up_Date_KeyPress(KeyAscii As Integer)
   Dim strKey As String
   Dim dateTODAY As Date
   Dim strTodaysDate As String

    ' Get todays date
        dateTODAY = DateTime.Date
        strTodaysDate = CStr(dateTODAY)

    ' Convert ANSI value to character string.
    strKey = Chr(KeyAscii)
    If strKey = "t" Then
        Me.Call_Up_Date.Text = strTodaysDate
    End If
End Sub

Thanks in advance

 
Old December 14th, 2006, 11:25 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Yikes. Why not just make the default value for the field Date() or Now()?



mmcdonal
 
Old December 14th, 2006, 11:29 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Okay, alternatively you can just add a button that does all this and give the user the option to click the button instead of typing a t. This is the functional equivalent of clicking a button anyway, and doesn't require knowledge of the secret letter to get today's date. Label the button "Enter today's date"




mmcdonal
 
Old December 19th, 2006, 07:29 PM
Authorized User
 
Join Date: Sep 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply...

The only thing is, it's not always todays date that is required.
and i would like to reduce the amount of buttons on screen.

Thanks again






Similar Threads
Thread Thread Starter Forum Replies Last Post
Big challenge here! How to convert char* to char^? samiswt Visual C++ 2005 1 November 30th, 2007 09:09 PM
onkeypress move to next control [except when the f kamii47 ASP.NET 2.0 Professional 2 September 11th, 2007 03:47 AM
unwanted conversion from char to ascii mor3bane C++ Programming 0 July 5th, 2007 03:07 AM
Invalid conversion from 'char*' to 'char' deuxmio C++ Programming 3 December 8th, 2006 07:56 AM
Onkeypress Fia VB.NET 2002/2003 Basics 0 May 6th, 2005 05:19 AM





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