Insert a date into a memo field. (1 Viewer)

N

NCWalker

Guest
I have an application that has a text box on a form that points to a memo data type.

On the form, I wish to allow the users to insert the system date with a short-cut key. (Trying to use Ctrl-D).

I have coded a Keypress Event that checks for the Ctrl-D. "Current" code is below:
===============================
Private Sub PM_Comments_KeyPress(KeyAscii As Integer)
Dim MyString As String
Dim MyDate As Variant

'Check to see if user pressed Ctrl-D
If KeyAscii = 4 Then

MyDate = Date
MyString = Format(MyDate, "Short Date") & ":"
SendKeys ("") ' Perhaps I need to dump the Ctrl-D in the buffer???
SendKeys (MyString)

End If

End Sub
==================================
I say current because I have tried MANY variations. The code is executing properly on the Ctrl-D. I have watched the variables in debug mode and they contain what I want, namely "mm/dd/yy:" for the current date. Problem is, it inserts the TIME in the memo field. And it is the system time, not the integer of the date formatted into the time.

Crazy thing is, in debug mode, the darn thing will do what I want and insert the date in the VB editor page. Just won't do it in the memo field on the form.

NCWalker
 

WayneRyan

AWF VIP
Local time
Today, 20:38
Joined
Nov 19, 2002
Messages
7,122
NC,

Insert the Date/Time at front:

Me.YourMemoControl = Now() & vbCrLf & Me.YourMemoControl

Insert the Date/Time at the end:

Me.YourMemoControl = Me.YourMemoControl & vbCrLf & Now()

Wayne
 
N

NCWalker

Guest
Sorry. Have a wrinkle. Wanting to insert the date at the current cursor position.

NCWalker
 
N

NCWalker

Guest
I have learned a little bit more, though.

Seems that the code executes while Ctrl is still held down. So the date that is typed by sendkeys is all typed as if it were manually entered WITH Ctrl held down.

Tried it with Shift-D and got it right, except it was all the shift characters above the numbers.

Easy fix is to just test for a non-raised character that won't be typed, like backwards apostophe. Or perhaps a function key.
 

Users who are viewing this thread

Top Bottom